How can i retrieve a key from a dictionary?

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Sun Nov 4 05:50:39 EST 2001


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

    HJ> how can one retrieve or select a key from a dictionary?
    HJ> dict={} dict[1]='one' dict[2]='two'

    HJ> dict.keys() will gets all the keys. but, i need to select
    HJ> explicitly one key for printing along its value.

Try this:

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

prabhu




More information about the Python-list mailing list