Lesson 012: Generator expressions and laziness
Focus
Treat the excerpt as executable notes: Intermediate drills Generator expressions and laziness; spin token 99958 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence2mixesGenerator expressions and laziness; spin52349. - Ritual: Describe falsifying evidence that would veto this pattern.
- Guardrail: name the surprise that triggered when literals shifted.
Example (LESSON_UID = "intermediate-012")
# Intermediate drill L012 topic-1 micro-1 pattern-4
LESSON_UID = "intermediate-012"
spin_a, spin_b, spin_c = 13, 697, 808
score = 58
ladder = []
ladder.append("bronze" if score < (spin_a % 41 + 1) 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-12.txt"
snap = [25, 43, 61, 79]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (808 + 131))
Practice
Practice 36: Promote hottest literal into named constant; justify naming aloud. Literal nudge 36.
Fingerprints
- lesson_uid:
intermediate-012 - umbrella band:
Generator expressions and laziness(2/10) - lesson_index:
360