Finding the most frequent element in a list — the mode — comes up in all kinds of analysis tasks: the most common word in a document, the most-ordered product, the most frequent error code in a log file. You could track counts manually with a dictionary and a loop, but Python's standard library already has a tool built exactly for this: collections.Counter.

Find the Most Frequent Element Using Counter

from collections import Counter

items = ["apple", "banana", "apple", "orange", "banana", "apple", "grape"]

counts = Counter(items)
print(f"Counts: {counts}")

most_common_item, frequency = counts.most_common(1)[0]
print(f"Most frequent: '{most_common_item}' ({frequency} times)")

Output:

Counts: Counter({'apple': 3, 'banana': 2, 'orange': 1, 'grape': 1})
Most frequent: 'apple' (3 times)

Counter(items) walks the list once and builds a dictionary-like object mapping each unique value to how many times it appeared — notice it even prints itself in a readable Counter({...}) format, already sorted from most to least common. .most_common(1) returns a list containing just the single top (item, count) tuple, which is why we immediately unpack index [0] out of it.

If you want the top 3 instead of just the single winner, counts.most_common(3) returns a list of three (item, count) tuples. Call .most_common() with no argument at all, and you get every item, fully ranked — effectively a frequency-sorted version of your original data.

The Manual Version, for Comparison

items = ["apple", "banana", "apple", "orange", "banana", "apple", "grape"]

freq = {}
for item in items:
    freq[item] = freq.get(item, 0) + 1

most_common_item = max(freq, key=freq.get)
print(f"Most frequent: '{most_common_item}' ({freq[most_common_item]} times)")

Both versions give the identical answer — Counter is just the built-in, well-tested, more readable way to express the exact same loop-and-dictionary logic, so it's generally what you'd reach for in real code rather than rewriting this pattern yourself every time.