Techblog
Counter in collections
Aggregating list with count of each element
The below code helps in counting each element the number of times it has occured in the same list.
Code:
from collections import Counter
l = [1,1,1,2,3,3,4,4,4,4]
i = Counter(l)
print(i)
Output:
No comments:
Post a Comment
Home
Subscribe to:
Comments (Atom)
No comments:
Post a Comment