Reputation: 2214
As someone here pointed me out, for getting the max duplicated item in a list this can be used:
>>> from collections import Counter
>>> mylist = [20, 20, 25, 25, 30, 30]
>>> max(k for k,v in Counter(mylist).items() if v>1)
30
but, what if i want to get the indexes instead of the values, being here [4, 5]
any help??
Regards...
Upvotes: 1
Views: 1150
Reputation: 133514
>>> from collections import defaultdict
>>> mylist = [20, 20, 25, 25, 30, 30]
>>> D = defaultdict(list)
>>> for i,x in enumerate(mylist):
D[x].append(i)
>>> D[max(k for k,v in D.items() if len(v)>1)]
[4, 5]
Upvotes: 3