def invert_dict(d):
inverse = dict()
for key in d:
val = d[key]
if isinstance(val, list):
for el in val:
if el not in inverse:
inverse[el] = [key]
else:
inverse[el].append(key)
else:
if val not in inverse:
inverse[val] = [key]
else:
inverse[val].append(key)
return inverse
Comments
Leave a comment