Lesson 121: collections.Counter, defaultdict, deque
Focus
Compare against yesterday's mental model politely: Intermediate drills collections.Counter, defaultdict, deque; spin token 1015291 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence1mixescollections.Counter, defaultdict, deque; spin44056. - Ritual: Mirror the snippet with reversed iteration order verbally.
- Guardrail: pick the budget that keeps this rehearsal honest.
Example (LESSON_UID = "intermediate-121")
# Intermediate drill L121 topic-12 micro-0 pattern-8
LESSON_UID = "intermediate-121"
spin_a, spin_b, spin_c = 53, 661, 874
pairs = [(53, 29), (0, 12), (8, 119)]
flat = 1
for left, right in sorted(pairs):
print(left ^ right + flat % 997)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-121.txt"
snap = [134, 191, 248]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (874 + 131))
Practice
Practice 4: Promote hottest literal into named constant; justify naming aloud. Literal nudge 4.
Fingerprints
- lesson_uid:
intermediate-121 - umbrella band:
collections.Counter, defaultdict, deque(1/10) - lesson_index:
3841