Lesson 130: collections.Counter, defaultdict, deque
Focus
Let the literals expose mistaken assumptions quickly: Intermediate drills collections.Counter, defaultdict, deque; spin token 1073911 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence10mixescollections.Counter, defaultdict, deque; spin32483. - Ritual: List two regressions CI should catch later.
- Guardrail: promise one security boundary if this touched user data.
Example (LESSON_UID = "intermediate-130")
# Intermediate drill L130 topic-12 micro-9 pattern-9
LESSON_UID = "intermediate-130"
spin_a, spin_b, spin_c = 90, 86, 751
def helper(x, bias=164):
return (x * bias + 9) % 5009
samples = [helper(130 + k) for k in range(3 + 12 % 4)]
print(samples, max(samples) - min(samples))
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-130.txt"
snap = [143, 246, 349, 452]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (751 + 131))
Practice
Practice 17: Rename locals for domain vocabulary-only; keep behaviour identical. Literal nudge 17.
Fingerprints
- lesson_uid:
intermediate-130 - umbrella band:
collections.Counter, defaultdict, deque(10/10) - lesson_index:
4192