Code: Select all
from collections import Counter
my_list = [1, 2, 3, 2, 1, 3, 2, 1]
my_counter = Counter(my_list)
print(my_counter) # Output: Counter({1: 3, 2: 3, 3: 2})
Code: Select all
myList = [1, 2, 3, 2, 1, 3, 2, 1]
groupby(count, myList, myList)
Verwendung: groupby(func, funcArgs, groupingCol). func muss eine Funktionsdefinition sein.
Interessanterweise funktioniert es ohne Syntaxfehler, wenn ich count durch avg ersetze (obwohl es mir nicht die Häufigkeit gibt, die ich brauche):
Code: Select all
groupby(avg, myList, myList) // This works and returns (1->1, 2->2, 3->3, but it is not desired output: {1: 3, 2: 3, 3: 2} )
Mobile version