0

Hi,

I basically have a dictionary with a few key value pairs in it.

mydict = {}
mydict['key1'] = 2000
mydict['key2'] = 3000
mydict['key3'] = 6000

I have read that you can check if a particular key is present in a dict with the 'in' statement like:

if 'key1' in mydict:
      do something

However, I need to check if a particular value is present in a dictionary. How do I go about doing that?

Thanks,
Adi

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by kadvar
0

Yes you can:

mydict = {}
mydict['key1'] = 2000
mydict['key2'] = 3000
mydict['key3'] = 6000

for x in range(1000,8000,1000):
    print x,(x in mydict.values()) and "is" or "is not", "in set"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.