[Tutor] How to print corresponding keys in Dictionary
bob gailer
bgailer at gmail.com
Tue Oct 25 00:50:33 CEST 2011
Another approach is to subclass dict such that each time you add a
key:value pair you also create an entry in a reverse dictionary. Then
all you need do is lookup in the reverse dictionary.
If there are several keys with the same value, then create and extend a
list of values in the reverse dictionary.
This will fail (as any other reverse dictionary approach will) if the
values are not hashable
--
Bob Gailer
919-636-4239
Chapel Hill NC
More information about the Tutor
mailing list