AI engineering glossary · Python advanced

What is counter?

Counter: A dictionary subclass in the collections module that counts how many times each item appears in an iterable. It offers helpers such as most_common() for ranking frequent items. It works like a tally sheet keyed by item, ideal for word frequencies.

Level: intermediateTopic: Python advanced

Counter: an example

Counter(words).most_common(3) returns the three most frequent words in a list of tokens.

Related terms

More Python advanced terms

Where you learn it

Counter is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.