I have a dictionary that has keys associated with lists.
mydict = {'fruits': ['banana', 'apple', 'orange'], 'vegetables': ['pepper', 'carrot'], 'cheese': ['swiss', 'cheddar', 'brie']}
What I want to do is use the if statement, which, if I look for the element and it in any of the lists in the dictionary, it will return the key. This is what I tried:
item = cheddar if item in mydict.values(): print key
but he does nothing, the conclusion should be:
cheese
This seems like a simple thing, but I just can't figure it out. Any help is awesome.
Binnie
source share