How can i retrieve a key from a dictionary?
Husam
h.jehadalwan at student.kun.nl
Sun Nov 4 09:00:40 EST 2001
Prabhu Ramachandran wrote:
> >>>>> "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
thanks, now i understand.
by the way, if you have time to satisfy my curuosity, what is the
solution for the umbiquity in you'r second example?
More information about the Python-list
mailing list