Searchable Python cheat sheet, 100+ idiomatic snippets
developers actually type — not hello-world filler.
Fifteen categories: basics (assign, numeric + Decimal,
bool, None, isinstance, range), string (f-string +
format spec, split / join, strip, replace + re.sub,
slicing, UTF-8), list (append vs extend trap,
comprehension with filter + ternary, sorted + key,
enumerate, zip strict, dedupe preserving order),
dict (.get, setdefault vs defaultdict, 3.9 | merge,
Counter), set (| & - ^ operators, frozenset, dedupe),
tuple (single-element comma, namedtuple, dataclass
with field(default_factory), *rest), control (if /
for-else / while, walrus :=, 3.10 match / case with
guards), function (mutable-default trap, lambda,
*args / **kwargs / keyword-only, type hints,
decorator + functools.wraps, partial), class
(__init__, @property, classmethod / staticmethod,
dunder, super + MRO, dataclass frozen + slots,
__enter__ / __exit__), file (encoding="utf-8" always,
pathlib, json ensure_ascii=False, csv newline="",
tempfile), exception (try / except / else / finally,
raise from, custom hierarchy, contextlib.suppress),
iter (next + default, yield, yield from, itertools
chain / groupby / permutations / accumulate,
functools.reduce + @lru_cache, zip_longest /
takewhile), async (asyncio.run, gather +
return_exceptions, create_task / timeout, async for
/ with, Queue + Semaphore, 3.11 TaskGroup), typing
(3.9 list[int], 3.10 X | None, TypedDict +
NotRequired, Protocol, TypeVar / Generic, Literal /
Final, cast / overload), and pitfalls (mutable
default, late-binding closure, shallow vs deep copy,
is vs ==, mutate while iterate, UnboundLocalError,
bare except, -7 // 2 == -4, O(n²) string concat).
Every entry: bilingual title, runnable code,
bilingual description, 1-2 variants. Search title /
code / description / variants together. 100% client-
side. Pair with SQL / curl / git / regex cheat
sheets and JSON Formatter.