Lesson 017: Generator expressions and laziness
Focus
Assume a reviewer executes this verbatim: Intermediate drills Generator expressions and laziness; spin token 155635 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence7mixesGenerator expressions and laziness; spin17216. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: call out latent off-by-one before shipping analogues.
Example (LESSON_UID = "intermediate-017")
# Intermediate drill L017 topic-1 micro-6 pattern-4
LESSON_UID = "intermediate-017"
spin_a, spin_b, spin_c = 410, 335, 43
score = 69
ladder = []
ladder.append("bronze" if score < (spin_a % 41 + 6) else "silver-ish")
ladder.append("gold" if score > (spin_b % 71 + 1) else "retry")
print(sorted(set(ladder)), score)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-17.txt"
snap = [30, 450, 870, 299, 719]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (43 + 131))
Practice
Practice 12: Rename locals for domain vocabulary-only; keep behaviour identical. Literal nudge 12.
Fingerprints
- lesson_uid:
intermediate-017 - umbrella band:
Generator expressions and laziness(7/10) - lesson_index:
555