Three weeks in. The collection algebra — sets, dict spread, zip, invert — how's the mental model feeling?
The set operators snapped into place fast. & for shared, | for combined. It's the exact math from high school, just with different punctuation.
That's the bridge. The patterns aren't new concepts; they're shorter notation for things you already understand intuitively.
The dict spread {**a, **b} I'm still warming to. I can read it but I want to make sure I know when to reach for it.
Six questions to lock everything in. Eighty percent to pass.
Set operators — a & b intersection (in both), a | b union (in either), a - b difference (in a, not b), a ^ b symmetric difference (in exactly one).
Dict spread {**a, **b} — merges two dicts into a new one. Later keys override earlier ones. Non-destructive.
dict(zip(keys, values)) — pairs two parallel lists into a dict. zip stops at the shorter iterable.
Dict inversion — {v: k for k, v in d.items()} swaps keys and values. Values must be hashable; duplicate values cause overwrites.
Common thread — every pattern this week is one expression. No loops, no mutable state, no index management.
Three weeks in. The collection algebra — sets, dict spread, zip, invert — how's the mental model feeling?
The set operators snapped into place fast. & for shared, | for combined. It's the exact math from high school, just with different punctuation.
That's the bridge. The patterns aren't new concepts; they're shorter notation for things you already understand intuitively.
The dict spread {**a, **b} I'm still warming to. I can read it but I want to make sure I know when to reach for it.
Six questions to lock everything in. Eighty percent to pass.
Set operators — a & b intersection (in both), a | b union (in either), a - b difference (in a, not b), a ^ b symmetric difference (in exactly one).
Dict spread {**a, **b} — merges two dicts into a new one. Later keys override earlier ones. Non-destructive.
dict(zip(keys, values)) — pairs two parallel lists into a dict. zip stops at the shorter iterable.
Dict inversion — {v: k for k, v in d.items()} swaps keys and values. Values must be hashable; duplicate values cause overwrites.
Common thread — every pattern this week is one expression. No loops, no mutable state, no index management.