Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ここで誰かが私に指摘したように、リスト内の最大重複アイテムを取得するには、これを使用できます。
>>> from collections import Counter >>> mylist = [20, 20, 25, 25, 30, 30] >>> max(k for k,v in Counter(mylist).items() if v>1) 30
しかし、値の代わりにインデックスを取得したい場合はどうなりますか?[4, 5]
[4, 5]
何か助けは?
よろしく...
>>> 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]