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.
メソッド l = [1,2,2,3,1,1,2,3,4,5,6] を使用したくないリストがあります。 l.count(element) for ループやイテレータは使いたくない。 のような出力 {1: 3, 2: 3, 3: 2, 4: 1, 5: 1, 6: 1}
l = [1,2,2,3,1,1,2,3,4,5,6]
l.count(element)
{1: 3, 2: 3, 3: 2, 4: 1, 5: 1, 6: 1}
Use collection's Counter:
Counter
>>> from collections import Counter >>> l = [1,2,2,3,1,1,2,3,4,5,6] >>> Counter(l) Counter({1: 3, 2: 3, 3: 2, 4: 1, 5: 1, 6: 1})