0

How to check whether '111' exists in dic1?

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

I tried using List comprehensions but unable to get the boolean answer? I got the error 'int' object is not iterable.

2
  • Can you please post some sample code? Commented Dec 7, 2017 at 17:19
  • @GaneshTata I am working an assignment on MongoDB and python. I got stuck at the problem which is similar to the above-mentioned piece of code.Thanks for your time. Commented Dec 7, 2017 at 17:25

1 Answer 1

2

You can iterate over dict.values and check for existence:

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

Output:

True 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, @Ajax1234 :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.