给定这样的字典:
my_map = {'a': 1, 'b': 2}
如何反转这张地图以获得:
inv_map = {1: 'a', 2: 'b'}
Python 3+:
inv_map = {v: k for k, v in my_map.items()}
蟒蛇2:
inv_map = {v: k for k, v in my_map.iteritems()}