felix001
felix001

Reputation: 16691

Matching key in Python dictionary

I have the following which works well for matching a key within a dictionary.

if mydict.__contains__('bananas'):
    print "found"

Is there a way to base the if on the logic that the string is not found

Upvotes: 0

Views: 458

Answers (1)

user647772
user647772

Reputation:

This is possible:

if "bananas" not in mydict:
    print "not found"

Upvotes: 8

Related Questions