I have a little code but I don't know how to find the key in a dictionary by using the value. Here I have my code and what I want to do:
NAMES = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank',
'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry']
AGES = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19]
def combine(list1,list2):
dictionary = dict(zip(list1,list2))
return dictionary
def people(age):
if leeftijd in dictionary:
return ['Bob']
print combine(NAMES, AGES)
print people(21) == ['Bob']
print people(22) == ['Kelly']
print people(23) == []
In this code I first put the list NAMES and AGES into a dictionary by using the combine function, but now I want to make a second function named people
that will output all the names of the people with the age you enter.
For example: if I enter 21 into that function, it should output Bob since Bob is the only one that's 21 years old.
I just have no idea how to do this since the AGE isn't the key in my dictionary and I also can't use an integer as a key.