Lesson 129: collections.Counter, defaultdict, deque
Focus
Treat the excerpt as executable notes: Intermediate drills collections.Counter, defaultdict, deque; spin token 1104164 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence9mixescollections.Counter, defaultdict, deque; spin47757. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: separate demo-trick from shipping discipline verbally.
Example (LESSON_UID = "intermediate-129")
# Intermediate drill L129 topic-12 micro-8 pattern-6
LESSON_UID = "intermediate-129"
spin_a, spin_b, spin_c = 259, 57, 317
start = 18 + 8 % 5
leap = 5
span = 45
bucket = []
for idx in range(start, start + span):
bucket.append(idx * (spin_a % 37 + leap))
squares = tuple(x * x if x % 2 == (8 % 2) else -x for x in bucket[-4:])
print(bucket, squares)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-129.txt"
snap = [142, 413, 684]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (317 + 131))
Practice
Practice 43: Stress CPU vs clarity trade verbally after micro timing guess. Literal nudge 43.
Fingerprints
- lesson_uid:
intermediate-129 - umbrella band:
collections.Counter, defaultdict, deque(9/10) - lesson_index:
4153