Lesson 043: Exceptions: catching, chaining, guarding
Focus
Compare against yesterday's mental model politely: Intermediate drills Exceptions: catching, chaining, guarding; spin token 353783 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence3mixesExceptions: catching, chaining, guarding; spin45974. - Ritual: Mirror the snippet with reversed iteration order verbally.
- Guardrail: name the surprise that triggered when literals shifted.
Example (LESSON_UID = "intermediate-043")
# Intermediate drill L043 topic-4 micro-2 pattern-2
LESSON_UID = "intermediate-043"
spin_a, spin_b, spin_c = 380, 952, 245
blob = "172|C"
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-43.txt"
snap = [56, 442, 828, 223, 609]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (245 + 131))
Practice
Practice 17: Promote hottest literal into named constant; justify naming aloud. Literal nudge 17.
Fingerprints
- lesson_uid:
intermediate-043 - umbrella band:
Exceptions: catching, chaining, guarding(3/10) - lesson_index:
1359