【发布时间】:2017-02-08 10:54:51
【问题描述】:
我有一个这样的字典和一个列表:
hey = {'2': ['Drink', 'c', 'd'], '1': ['Cook', 'a']}
temp = ['Cook', 'a']
我想检查temp 是否存在于hey 中。我的代码:
def checkArrayItem(source,target):
global flag
flag = True
for item in source:
if (item in target):
continue
else:
flag = False
break
for i,arr in enumerate(hey) :
if (len(temp) == len(hey[arr])):
checkArrayItem(temp,hey[arr])
if (flag):
print('I got it')
break
有什么更优雅的方式来做这个检查?
【问题讨论】:
-
你的意思是你有一个
dict和一个list。 -
谢谢,我看到了链接。
标签: python