How would you get all indexes of the duplicate items as well as the unique items from a list and put it into a dictionary. I want to write a code that doesn’t use the enumerate function and set function as shown below
x = [1.2, 2.4, 3.1, 4.0, 5.6, 6.5, 1.2, 3.1, 8.1, 23.6, 29.3]
Dictionary = {}
for i in set(x):
if x.count(i) > 1:
Dictionary[i] = [str(index) for index, value in enumerate(x) if value == i]
Print(Dictionary)
I hope to get an output as follows:
{1.2:[0,6],2.4:[1],3.1:[2,7]...}