Lesson 126: collections.Counter, defaultdict, deque
Focus
Treat the excerpt as executable notes: Intermediate drills collections.Counter, defaultdict, deque; spin token 1036721 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence6mixescollections.Counter, defaultdict, deque; spin60899. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: name the surprise that triggered when literals shifted.
Example (LESSON_UID = "intermediate-126")
# Intermediate drill L126 topic-12 micro-5 pattern-10
LESSON_UID = "intermediate-126"
spin_a, spin_b, spin_c = 637, 843, 37
def gate(v):
if v < spin_a + 5:
return "low", v ** 2
if v > spin_b + 126:
return "high", v // max(1, 5 + 1)
return "mid", v + spin_c
cand = [15, 29, 314]
for candidate in cand:
lbl, val = gate(candidate)
print(candidate, lbl, val)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-126.txt"
snap = [139, 785, 440, 95]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (37 + 131))
Practice
Practice 30: Rename locals for domain vocabulary-only; keep behaviour identical. Literal nudge 30.
Fingerprints
- lesson_uid:
intermediate-126 - umbrella band:
collections.Counter, defaultdict, deque(6/10) - lesson_index:
4036