Lesson 016: Generator expressions and laziness
Focus
Prints are breadcrumbs, not ornamentation: Intermediate drills Generator expressions and laziness; spin token 188628 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence6mixesGenerator expressions and laziness; spin28172. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: promise one security boundary if this touched user data.
Example (LESSON_UID = "intermediate-016")
# Intermediate drill L016 topic-1 micro-5 pattern-2
LESSON_UID = "intermediate-016"
spin_a, spin_b, spin_c = 832, 806, 412
blob = "16|F"
head, sep, tail = blob.partition("|")
print(tuple(zip(head, reversed(tail))))
filt = [ch for ch in head if ord(ch) % (spin_a % 5 + 2) != 0]
print("filt", filt)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-16.txt"
snap = [29, 870, 720, 570]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (412 + 131))
Practice
Practice 33: Clone twice: expand literals vs shrink loops; compare narrative. Literal nudge 33.
Fingerprints
- lesson_uid:
intermediate-016 - umbrella band:
Generator expressions and laziness(6/10) - lesson_index:
516