Question: ❓❓❓


I made a function which will look up ages in dictionary and show the matching name:

list = {'george':16,'amber':19}
search_age = raw_input("Provide age")
for age in list.values():
    if age == search_age:
        name = list[age]
        print name

I know how to compare and find the age I just don’t know how to show the name of the person. Additionally, I am getting a KeyError because of line 5. I know it’s not correct but I can’t figure out to make it search backwards.


Good Answer: 👌👌👌

There is none. dict is not intended to be used this way.

for name, age in list.iteritems():
    if age == search_age:
        print name

Read More: 👉 https://stackoverflow.com/questions/8023306/get-key-by-value-in-dictionary