What would be the Pythonic way to check if ANY element in a list is a key in a dictionary?
Example, I have a list of fruits:
fruits = ['apples', 'bananas', 'pears']
And want to check if ANY fruit is a key in my dictionary, examples:
fruit_dict1 = {'apples': 4, 'oranges': 3, 'dragonfruit': 4} returns True
fruit_dict2 = {'oranges': 3, 'dragonfruit': 9, 'pineapples': 4} returns False
So far I have:
def fruit_checker(list, dict):
for fruit in list:
if fruit in dict:
return True
return False
It feels weird to just look for a fruit "in" a dictionary, but it seems "in" only does a search on dictionary keys. How exactly does "in" work with the different types?