[英]How to Check whether a element exists in a python dictionary value which is a list?
如何檢查dic1
是否存在'111'
?
dic1 = {'images':[000,111,222,333,444],'name':['foo','bar','baz']}
我嘗試使用列表推導,但無法獲得布爾答案? 我得到了錯誤'int' object is not iterable
。
您可以遍歷dict.values
並檢查是否存在:
dic1 = {'images':[000,111,222,333,444],'name':['foo','bar','baz']}
print(any(111 in b for b in dic1.values()))
輸出:
True
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.