Given a dictionary like so:
my_map = {\'a\': 1, \'b\': 2}
How can one invert this map to get:
inv_map = {1: \'a\', 2: \'b\'
I wrote this with the help of cycle 'for' and method '.get()' and I changed the name 'map' of the dictionary to 'map1' because 'map' is a function.
def dict_invert(map1): inv_map = {} # new dictionary for key in map1.keys(): inv_map[map1.get(key)] = key return inv_map