Count Things with Counter

Talk it through out loud with your AI coach.

The problem

  • easy
  • Pro

You need the ten most common words in a large text, and your first version uses a plain dictionary with an if statement to check whether each word is already a key. Explain how the Counter class from Python's collections module simplifies this.

What a strong answer covers

  • What the Counter type is and how it relates to a dictionary.
  • Building the counts in one step rather than a hand-written loop.
  • Getting the most frequent items out directly.
  • How Counter behaves for items it has never seen.

Common mistake: Sorting the whole dictionary by hand to find the top ten, when Counter already provides that.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud