this = '['123','231','34','123','34','123']'
dups = collections.defaultdict(list)
for i, item in enumerate(this):
for j, orig in enumerate(seen):
if item == orig:
dups[j].append(i)
break
else:
seen.append(item)
I have this code.
What I want to do is to print out the indexes of each element so its in the form [('123',[0,3,5]),('231',[1]),('34',[2,4])]
however my code produces [('123',[3,5]),('34',[4])]
Is there anyway I can edit my code so it produces the answer I want without changing the form of the array so the output will stay as
[('123',[0,3,5]),('231',[1]),('34',[2,4])]