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

Python Advanced — 139: Decode closure capture with defensive defaults centred on `Pattern matching and union ergonomics` [85281]

Lesson 139: Pattern matching and union ergonomics

Focus

Compare against yesterday's mental model politely: Advanced drills Pattern matching and union ergonomics; spin token 1155432 makes this page unlike its neighbours.

Key ideas

Example (LESSON_UID = "advanced-139")

# Advanced drill L139 topic-13 micro-8 pattern-3
LESSON_UID = "advanced-139"
spin_a, spin_b, spin_c = 52, 300, 912

sentinel = ([] or [])
sentinel = sentinel or [3]
print(bool(sentinel), sentinel)
pick = sentinel or "fallback-8"
print("chosen", pick)

from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as scratch:
    target = Path(scratch) / "scratch-139.txt"
    snap = [152, 216, 280]
    target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
    print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (912 + 131))


import asyncio

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

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

asyncio.run(harness(86351))

Practice

Practice 26: Enumerate three pytest markers you'd decorate if this lived in CI. Literal nudge 26.

Fingerprints