inv_map = {v: k for k, v in my_map.items()}
# Invert a dictionary that can have several keys mapping to the same value
# In the inverse dictionary every value is mapped to the list of its keys
D={'a':1, 'b':1, 'c':2, 'd':2, 'e':3}
D_inv={}
for k,v in D.items(): D_inv[v]=D_inv.get(v,[])+[k]
d = {'a':1, 'b':2, 'c':3}
inverted_d = {}
for k, v in d.items():
inverted_d[v] = k
my_dict = dict(map(reversed, my_dict.items()))
inv_map = {v: k for k, v in my_map.iteritems()}
inv_map = {v: k for k, v in my_map.iteritems()}