[Solved] Python: build dictionary from list


from collections import defaultdict
d = defaultdict(list)
for i,j in enumerate(x):
    d[j].append(i)

Using defaultdict with the default being empty list and enumerate to provide the index

solved Python: build dictionary from list