Dev Helpers

Python / Collections

Read the most common element

Dev Helpers · March 8, 2026

A frequency table preserves counts that a set would lose. Counter can return ranked entries without a custom counting loop.

Worked example

from collections import Counter
print(Counter([3, 1, 3, 2, 3]).most_common(1))

Result

[(3, 3)]

Implementation notes

Counting hashable values groups by equality. Normalize casing or whitespace first only if those differences should disappear from the report.

Try it yourself

Add a tie and check whether you need a secondary ordering rule.

Open the Python example →

Editorial date March 8, 2026 · Published December 6, 2026

Related articles

Run an async function

An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.

Transpose a matrix

Transposing rows into columns assumes a decision about uneven rows. Ordinary zip stops at the shortest input.

Unpack with a remainder

Starred unpacking separates a fixed header from a variable-length tail. It still requires enough elements for the fixed positions.