The rules, again
Same game as chapter 1: read the question, commit to a prediction, run it, and only then open the answer. Wrong prediction means the drill goes on your redo list for three days from now.
This chapter closes the core tier. Four modules, collections, itertools, datetime, and re, cover most of the helper code Python programmers stop writing by hand. Knowing them is also an interview signal: Counter in an anagram problem or deque in a BFS says fluent, the hand-rolled version says tourist.
Skim the official tutorial's Brief Tour of the Standard Library and learnpython.org's Regular Expressions first, then come back and drill.
One idea before you start
The phrase you will hear about Python's stdlib is "batteries included". Here is what that buys you in practice.
The drills
Click a question to open it. The answer stays hidden until you ask for it. Predict first.
Want more drills?
When these stop surprising you, let an AI generate fresh ones. Copy this prompt into ChatGPT, Claude, or any assistant you like:
You are my Python drill coach. Quiz me on: collections (Counter,
defaultdict, deque, namedtuple), itertools (islice, chain, groupby,
combinations/permutations/product), datetime (timedelta, strptime,
naive vs aware), and re (match vs search, greedy vs lazy, findall,
raw strings).
Rules:
- Ask ONE question at a time. Show a short code snippet and ask me to
predict the output (or the error) before running it.
- Wait for my answer. Do not reveal anything until I reply.
- If I am right, say so in one line and raise the difficulty slightly.
- If I am wrong, explain the why in 2-3 sentences, then give me a
similar question later to check I really got it.
- Prefer tricky edge cases over textbook questions: defaultdict
creating keys on read, groupby on unsorted data, comparing naive and
aware datetimes, .group() on a failed match, greedy .* overshooting.
- Keep score. After 10 questions, list the concepts I missed so I can
add them to my redo list.
Start with a medium question.The predict-first rule matters more than the tool. Whatever generates the questions, always commit to an answer before you look.
Done?
Score yourself honestly and queue up your misses. The three that separate fluent from familiar: drill 3 (defaultdict lookups are writes), drill 7 (groupby needs sorted input), and drill 13 (greedy overshoot). Each one is a production bug that passed review somewhere this week.
That closes the core tier, chapters 1 to 10. From here the series shifts to the interview tier: typing, decorators, testing, and async, the four topics that decide senior Python interviews. Next up: type hints, dataclasses, and Protocol.