I have this list: [1, 2, 3, 6, 1, 3]
I'm trying to get the indexes of the list elements that are duplicates. In this case, the code should return 0, 4, because there are duplicate elements at the 0th and 4th indexes. However, when I run my code, my output only shows 4, for the 4th index, and does not print out the 0th index as well. Can anyone help me find the problem in the code?
lst = [1, 2, 3, 6, 1, 3]
oc_set = set()
res = []
for idx, val in enumerate(lst):
if val not in oc_set:
oc_set.add(val)
else:
res.append(idx)
print(res)
Output:
[4] [4]