[dictionary] how to get key by item
Egor Bolonev
ebolonev at mail.ru
Mon Dec 13 19:51:24 EST 2004
saluton al ciuj
i know how to get item by key
==================
dict = {10 : 50, 2 : 12, 4 : 43}
print dict[2]
>> 12
but i wonder how to get key by item
print dict[12]
>> 2
==================
is there a more fast way than that one (my dictionary is really big)
==================
dict = {10 : 50, 2 : 12, 4 : 43}
item = 12
for key in dict.keys():
if dict[key] == item:
print key
break
==================
More information about the Python-list
mailing list