Lesson 020: Generator expressions and laziness
Focus
Anchor one invariant before you branch mentally: Intermediate drills Generator expressions and laziness; spin token 195303 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence10mixesGenerator expressions and laziness; spin23387. - Ritual: Freeze one literal constant with a purposeful name aloud.
- Guardrail: separate demo-trick from shipping discipline verbally.
Example (LESSON_UID = "intermediate-020")
# Intermediate drill L020 topic-1 micro-9 pattern-8
LESSON_UID = "intermediate-020"
spin_a, spin_b, spin_c = 329, 442, 561
pairs = [(37, 47), (9, 1), (20, 108)]
flat = 19
for left, right in sorted(pairs):
print(left ^ right + flat % 997)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-20.txt"
snap = [33, 375, 717, 68]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (561 + 131))
Practice
Practice 23: Promote hottest literal into named constant; justify naming aloud. Literal nudge 23.
Fingerprints
- lesson_uid:
intermediate-020 - umbrella band:
Generator expressions and laziness(10/10) - lesson_index:
672