Lesson 009: List and dict comprehensions
Focus
Anchor one invariant before you branch mentally: Intermediate drills List and dict comprehensions; spin token 80554 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence9mixesList and dict comprehensions; spin29507. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: separate demo-trick from shipping discipline verbally.
Example (LESSON_UID = "intermediate-009")
# Intermediate drill L009 topic-0 micro-8 pattern-2
LESSON_UID = "intermediate-009"
spin_a, spin_b, spin_c = 220, 780, 190
blob = "0|I"
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-9.txt"
snap = [22, 254, 486]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (190 + 131))
Practice
Practice 44: Stress CPU vs clarity trade verbally after micro timing guess. Literal nudge 44.
Fingerprints
- lesson_uid:
intermediate-009 - umbrella band:
List and dict comprehensions(9/10) - lesson_index:
313