How can i retrieve a key from a dictionary?

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Sun Nov 4 07:13:24 EST 2001


>>>>> "HJ" == Husam <h.jehadalwan at student.kun.nl> writes:

    >> dict.keys()[dict.values().index('one')]
    >> 
    >> prabhu

    HJ> it works, but wat does the -index- means?

>>> a = []
>>> print a.index.__doc__
L.index(value) -> integer -- return index of first occurrence of value

Also, note the above might give you unexpected results if you have two
different keys that have the same value i.e. if you did:

dict[3] = 'one'

You'd have two keys pointing to the same 'one' in this case you are in
for trouble.

prabhu




More information about the Python-list mailing list