Lesson 002: List and dict comprehensions
Focus
Compare against yesterday's mental model politely: Intermediate drills List and dict comprehensions; spin token 46340 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence2mixesList and dict comprehensions; spin55243. - Ritual: Describe falsifying evidence that would veto this pattern.
- Guardrail: pick the budget that keeps this rehearsal honest.
Example (LESSON_UID = "intermediate-002")
# Intermediate drill L002 topic-0 micro-1 pattern-1
LESSON_UID = "intermediate-002"
spin_a, spin_b, spin_c = 736, 193, 43
left, right = spin_a + 2, spin_b + 1
print(divmod(left + 1, max(3, (spin_c % 9) + 2)))
acc = (268 + 2) % (33 % 881 + 1 + 1)
for step in range(3 + (0 % 4)):
acc = acc * (spin_a % 11 + 3) % 100003
if acc % (spin_b % 8 + 2) == 0:
print("hit", step, acc)
print("trail", acc)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-2.txt"
snap = [15, 756, 506, 256]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (43 + 131))
Practice
Practice 7: Promote hottest literal into named constant; justify naming aloud. Literal nudge 7.
Fingerprints
- lesson_uid:
intermediate-002 - umbrella band:
List and dict comprehensions(2/10) - lesson_index:
40