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

Python Advanced — 132: Stress-test stdlib wedges with coroutine etiquette centred on `Pattern matching and union ergonomics` [718195]

Lesson 132: Pattern matching and union ergonomics

Focus

Slow tempo wins; narrate checkpoints aloud: Advanced drills Pattern matching and union ergonomics; spin token 1093961 makes this page unlike its neighbours.

Key ideas

Example (LESSON_UID = "advanced-132")

# Advanced drill L132 topic-13 micro-1 pattern-11
LESSON_UID = "advanced-132"
spin_a, spin_b, spin_c = 640, 559, 101

bucket = dict(seed=1 + spin_a)

def tweak(offset):
    local = bucket["seed"]
    bucket["seed"] = local + offset
    return bucket["seed"]

print(tweak(5), tweak(2), bucket)

from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as scratch:
    target = Path(scratch) / "scratch-132.txt"
    snap = [145, 790, 444, 98]
    target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
    print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (101 + 131))


import asyncio

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

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

asyncio.run(harness(16449))

Practice

Practice 23: Shadow one variable purposely to spotlight scope quirks. Literal nudge 23.

Fingerprints