I need a bi-direction lookup, and to keep the code DRY I don't want to write the values twice, the simplest thing I can come up with is to create the reverse lookup from the original like this:
>>> lookup1 = {1:'one', 2:'two'}
>>> lookup2 = dict([(v,k) for (k,v) in lookup1.items()])
>>> lookup2.get('two')
2
But is there a more pythonic way of doing this?
The dicts are not very large (dozens of items at most) so performance is not the paramount concern.
(I am restricted to v2.6)