Possible Duplicate:
Most efficient method to get key for a value in a dict
Python: Modify a dict to make the key a value, and a value the key
In python, suppose we have a dictionary:
mydict = {'myKey': 'myValue'}
To get the value for myKey we do
myDict['myKey']
Suppose we need to do things the other way around.
What is the easiest way to get the key for value my value?
Note: In this case my dictionary is static. The entries never change.
You could create a ‘reversed’ dictionary, since the initial dictionary is static: