[ad_1]
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
[ad_2]
solved Python: build dictionary from list
[ad_1]
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
[ad_2]
solved Python: build dictionary from list