Count a single value with .count()

items = ["a", "b", "a", "c", "a"]
print(items.count("a"))   # 3

count scans the list and returns how many times the value appears. It is the quickest option when you only care about one value.

Count every value with Counter

from collections import Counter

items = ["a", "b", "a", "c", "a"]
counts = Counter(items)
print(counts)   # Counter({"a": 3, "b": 1, "c": 1})
print(counts["b"])   # 1

Counter tallies everything in one pass, and you can look up any value just like a dictionary.

Find the most common values

from collections import Counter

words = ["red", "blue", "red", "green", "red", "blue"]
print(Counter(words).most_common(2))   # [("red", 3), ("blue", 2)]

most_common(n) returns the top n values sorted from highest count to lowest — ideal for finding the most frequent items.

Which method should you use?

  • list.count — when you need the count of a single value.
  • Counter — when you need counts for many or all values.
  • most_common — when you want the top items ranked.
  • Common mistake: calling count in a loop over every item, which scans the list repeatedly and is slow.

Frequently asked questions

Is Counter faster than calling count in a loop?

Yes. Counter tallies all values in a single pass, while calling count once per item rescans the whole list each time.

How do I count items that match a condition?

Use a generator with sum: sum(1 for x in items if x > 10) counts how many values are greater than 10.

Want to learn the collections module and more? Our free Python course covers it.