0%

The Standard Library Exists · practice

Count with Counter

The briefing’s second job is to count activity categories. You could build a and branch on whether every category has appeared before. That code is possible, but the job itself is common enough to have a standard-library name: Counter.

The collections.Counter constructor accepts an of hashable values. It returns a dictionary subclass whose values are counts:

Try it

The missing category prints 0. A regular dictionary lookup would raise . That difference belongs to Counter’s public contract and is one reason it fits this job.

Separate counting from presentation

Our records are dictionaries:

{"date": "2026-08-03", "category": "walk", "minutes": 35}

Counter needs the category values, not whole dictionaries. Build a of those values, then pass the list to Counter.

Do not format a sentence yet. A Counter is useful data that the capstone can order and present later. Counter remembers encounter order, but encounter order is not an alphabetical report contract. Keeping those decisions separate will make the final output deterministic.

What should count_categories(records) pass to Counter?

Add the second to the same workspace file. The editor merges the new starter definition without replacing the days_between work you already completed.

Task

Implement count_categories(records) in activity_report.py.

Each record is a with date, category, and minutes keys.

  1. Visit every record and collect its category .

  2. Construct and return a collections.Counter from those categories.

  3. For an empty , return an empty Counter naturally.

Keep returning data rather than a formatted sentence. The capstone will decide how counts should appear.