如何检查作为列表的python字典值中是否存在元素?

时间:2017-12-07 17:17:18

标签: python dictionary list-comprehension

如何检查'111'中是否存在dic1

dic1 = {'images':[000,111,222,333,444],'name':['foo','bar','baz']}

我尝试使用List comprehensions但无法得到布尔答案?我收到错误'int' object is not iterable

1 个答案:

答案 0 :(得分:2)

您可以迭代dict.values并检查是否存在:

dic1 = {'images':[000,111,222,333,444],'name':['foo','bar','baz']}
print(any(111 in b for b in dic1.values()))

输出:

True