To do reverse / invert a mapping in Python 2.7.x you can use the following piece of code:-
my_map = { 'a': 1, 'b':2 }
inv_map = {x: i for i, x in my_map.iteritems()}
Print inv_map
If you want to do reverse / invert a mapping you can use the following piece of code:-
my_map = { 'a': 1, 'b':2 }
inv_map = {x: i for i, x in my_map.items()}
print(inv_map)