Working With Data
Working with Data
Tier 2 — the core data structures and the comprehensions that operate on them. A deep pass on sequences (list/tuple/str as one protocol), dictionaries and sets and the hashing that powers them, comprehensions, and strings in depth. Where you stop writing loops for everything.
Suggest an editWorking with Data
Tier 1 gave you lists and loops. Tier 2 turns those into fluency with data structures — the containers that make programs fast and expressive — and the comprehensions that build them in a single line. The thesis of the tier: most everyday Python is choosing the right container and transforming it, and the right choice is dictated by the operation you do most (lookup, ordering, uniqueness).
Four chapters, in order:
- Sequences & the Sequence Protocol — list, tuple, and string as three implementations of one abstraction; the deep pass on indexing, slicing, and complexity.
- Dictionaries & Sets — key→value maps and unique collections, both powered by hashing and O(1) lookup.
- Comprehensions — building lists, dicts, and sets (and lazy generators) in one readable expression.
- Strings in Depth — the format mini-language, text algorithms, and why naïve string-building is quadratic.
These chapters assume Tier 1: you should be comfortable with lists, loops, and booleans. Several are deep passes that revisit a gentle Tier-0/1 topic with full rigour, referencing the earlier chapter rather than repeating it.
📘 How to read the Intuition boxes. Each one is built in three moves:
- The mechanism — what the interpreter is actually doing.
- A concrete bite — a specific, runnable way the naive assumption fails.
- The earned rule — the decision heuristic, now justified rather than asserted, plus its cost.