I made a function which will look up ages in dictionary and give out there name

my dictionary si for example {george:16,amber:19}


i made this

search_age = raw_input("Provide age")
	for age in list.values():
		if age == search_age:
			name = list[age]
			print name

but i know how to compare and find the age i just dont know how to show the name of the person, additionally i am getting key error, i know it because of line 4, i know its not correct but i cant figure out to make it search backwards.

any help would be appreciated

Thanks in advance

list is builtin type, I do not understand list.items. Your indention also seems incorrect.

but i know how to compare and find the age i just dont know how to show the name of the person

You want to use

for key, item in a_dictionary.items():
#
# or
for key in a_dictionary:
    if a_dictionary[key] == age:
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.