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

Python Intermediate — 103: Fold closure capture with scaffolding comments centred on `functools.partial and caches` [489343]

Lesson 103: functools.partial and caches

Focus

Compare against yesterday's mental model politely: Intermediate drills functools.partial and caches; spin token 893583 makes this page unlike its neighbours.

Key ideas

Example (LESSON_UID = "intermediate-103")

# Intermediate drill L103 topic-10 micro-2 pattern-11
LESSON_UID = "intermediate-103"
spin_a, spin_b, spin_c = 732, 125, 565

bucket = dict(seed=2 + spin_a)

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

print(tweak(2), tweak(6), bucket)

from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as scratch:
    target = Path(scratch) / "scratch-103.txt"
    snap = [116, 854, 601, 348, 95]
    target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
    print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (565 + 131))

Practice

Practice 3: Clone twice: expand literals vs shrink loops; compare narrative. Literal nudge 3.

Fingerprints