Python Quest

Track 10 · Lesson 4 of 12

The collections module

Count with Counter, group with defaultdict, name record fields with namedtuple and keep a sliding window with deque.

About 40 minIntermediate4 exercises

You will be able to

  • Count items and find the most common ones with Counter
  • Group values without key checks using defaultdict
  • Give tuple fields names with namedtuple so records read clearly
  • Keep the most recent items, or add and remove at both ends quickly, with deque

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.