Invert dictionary
Inverts a dictionary with non-unique hashable values.
- Create a
collections.defaultdict
withlist
as the default value for each key. - Use
dictionary.items()
in combination with a loop to map the values of the dictionary to keys usingdict.append()
. - Use
dict()
to convert thecollections.defaultdict
to a regular dictionary.