Counter
noun
say it: “KOWN-ter” /ˈkaʊntər/
In Python, a tool from the collections module that counts how many times each item in a list appears and can list the most common ones.
What is a Counter?
A Counter counts how many times each item appears and can tell you the most common ones.
from collections import Counter
votes = ["pizza", "tacos", "pizza", "sushi", "pizza"]
print(Counter(votes).most_common(1)) # [('pizza', 3)]
In a sentence
- “She used a Counter to find which loaf sold most often.”
- “A Counter of the votes showed pizza won with 3.”
Level: Freelancer · More Python terms at this level
Updated