← Curriculum track ← Learn hub
Quanta GenAI Curriculum · Python · Intermediate

Python Intermediate — 020: Guard async relays with scaffolding comments centred on `Generator expressions and laziness` [619666]

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

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