Counter and defaultdict in Action
Tally items without missing-key errors.
Tallying Made Easy
Counting how often things appear is everywhere in contests. The collections module gives two tools that make tallying painless. 🧮
The Missing-Key Problem
Plain dicts raise a KeyError when you increment a key that does not exist yet. Special structures remove that friction for you.
All lessons in this course
- Sets for Membership and Dedup
- Dictionaries as Lookup Tables
- Counter and defaultdict in Action
- Group and Bucket with a Map