Dictionaries inside out
Burton Samograd
burton at userful.com
Fri Nov 26 13:15:11 EST 2010
Greg Lindstrom <gslindstrom at gmail.com> writes:
> I am working on a project where I'm using dictionaries to hold the
> translations to codes (i.e., {'1':'Cheddar','2':'Ice
> Hockey','IL':'Thermostat Broken'}). The bulk of the application
> requires me to translate codes to their meaning, but it would be nice
> to be able to translate a meaning back to the original code as well.
> This seems to me like it must be a common situation that has been
> addresses/solved by those smarter than me. Is there, dare I say, a
> design pattern for this problem? Is there a better way of approaching
> it other than making a set of dictionaries which "mirror" the
> originals? FWIW, I have approximately 50 tables ranging from 2
> entries to over 100.
Looks like there might be some solutions here:
http://stackoverflow.com/questions/483666/python-reverse-inverse-a-mapping
--
Burton Samograd
More information about the Python-list
mailing list