Append to list in python dict comprehension
A more sophisticated way to do it:
out = {}
for key, val in inp.items():
out.setdefault(val, []).append(key)
A more sophisticated way to do it:
out = {}
for key, val in inp.items():
out.setdefault(val, []).append(key)