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

Recommended Answers

All 3 Replies

if 'key1' in mydict.values():
      do something

that should do it.

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"

Thanks that worked!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.