我有一个字典和像这样的列表:检查清单,给定的项目出现在字典
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'。 – khelwood
谢谢,我已经看到链接。 –