Other tricks with dictionaries ( was Stupid Python Trick #2 )

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Fri, 17 Sep 1993 12:56:38 -0400

I pretty much ignored the discussion that followed the proposal that
dictionary mappings be extended to have keys other that type string.

I really didn't see a need for them myself ( at the time ) - you could
always use `thing` as the key string.

But now that they ARE arbitrarily indexable - I have discovered that
the REALLY neat thing is that dictionaries are now INVERTABLE.

This is sometimes and easy solution to an awkward problem.

Please excuse me if this was the obvious point of the whole proposal.
I may have been too dense at the time to figure that out, but it
now looks like such an obvious trick now, that I have even used it
when it wasn't necessary: i.e. the special case where I was mapping
from strings to integers, could be reverse mapped with a list of
strings where list.index( 'string' ) == dict['string']. The more
general solution of building an inverse dictionary may have much
wider uses.

-Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
-Univ. of Virginia Department of Molecular Physiology and Biological Physics