Lesson 007: List and dict comprehensions
Focus
Anchor one invariant before you branch mentally: Intermediate drills List and dict comprehensions; spin token 83082 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence7mixesList and dict comprehensions; spin25209. - Ritual: Swap one benign literal twice to see binding effects.
- Guardrail: promise one security boundary if this touched user data.
Example (LESSON_UID = "intermediate-007")
# Intermediate drill L007 topic-0 micro-6 pattern-7
LESSON_UID = "intermediate-007"
spin_a, spin_b, spin_c = 627, 135, 94
src = [((k + 7) * spin_a + 6) % 241 for k in range(4 + 6 % 3)]
derived = [v * v if v % 2 == 0 else v + spin_b for v in src]
print("src", src)
print("derived", derived)
print("zip_sum", sum(x + y for x, y in zip(src, derived)))
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-7.txt"
snap = [20, 657, 303, 940, 586]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (94 + 131))
Practice
Practice 8: Stress CPU vs clarity trade verbally after micro timing guess. Literal nudge 8.
Fingerprints
- lesson_uid:
intermediate-007 - umbrella band:
List and dict comprehensions(7/10) - lesson_index:
235