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

Python Advanced — 138: Guard dict views with timing humility centred on `Pattern matching and union ergonomics` [741998]

Lesson 138: Pattern matching and union ergonomics

Focus

This page is deliberate repetition with new literals: Advanced drills Pattern matching and union ergonomics; spin token 1167828 makes this page unlike its neighbours.

Key ideas

Example (LESSON_UID = "advanced-138")

# Advanced drill L138 topic-13 micro-7 pattern-3
LESSON_UID = "advanced-138"
spin_a, spin_b, spin_c = 705, 844, 787

sentinel = ([] or [])
sentinel = sentinel or [2]
print(bool(sentinel), sentinel)
pick = sentinel or "fallback-7"
print("chosen", pick)

from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as scratch:
    target = Path(scratch) / "scratch-138.txt"
    snap = [151, 867, 592, 317, 42, 758]
    target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
    print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (787 + 131))


import asyncio

async def finalize(seed, spin):
    await asyncio.sleep(0)
    blend = (seed * 131 + 13 * (13 % 997) + 7 * (7 % 853) + spin) % 900001
    return blend

async def harness(loop_seed):
    print("async_result", await finalize(loop_seed, 19123))

asyncio.run(harness(76365))

Practice

Practice 36: Export checkpoints into bullets for teammate review. Literal nudge 36.

Fingerprints