import collections

def revert_dict(d):
    rd = collections.defaultdict(list)
for key, value in d.items():
    rd[value].append(key)
return rd
smarter "reverse" of a dictionary in python (acc for some of values being the same)?