Run an async function
An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.
Developer journal
Practical notes on iterators, dictionaries, data processing and the standard library.
An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.
Transposing rows into columns assumes a decision about uneven rows. Ordinary zip stops at the shortest input.
Starred unpacking separates a fixed header from a variable-length tail. It still requires enough elements for the fixed positions.
A page number and offset are the quotient and remainder of the same division. divmod returns both from one operation.
Padding belongs to the display form of an identifier. Keeping IDs as strings preserves meaningful leading zeroes.
Assertions make assumptions visible in tests. Python can disable them in optimized execution, so required input validation deserves an explicit exception.
A compound extension such as .tar.gz describes more than a final suffix. pathlib exposes the suffix list without manual string slicing.
A symmetric difference contains values found on exactly one side. It works well for comparing membership snapshots where multiplicity is irrelevant.
A timeout limits how long a caller waits and can cancel work inside its scope. Cleanup needs to survive cancellation.
When a dashboard needs only a few leaders, a top-k operation avoids constructing a complete sorted report. Keep the desired output order explicit.
A one-level flatten turns a sequence of groups into a sequence of members. Deeper lists remain members in their own right.
A frequency table preserves counts that a set would lose. Counter can return ranked entries without a custom counting loop.
Integer square roots avoid rounding a large count through a floating-point value. The result is the largest integer whose square fits.
Human-facing row numbers often start at one while sequence indexes start at zero. enumerate accepts a display offset directly.
ascii gives diagnostic text an ASCII-only representation. Escapes in the result describe the characters and do not change the source string.
Sorting JSON keys makes snapshots easier to compare. Array order remains significant and is preserved.
An ordered dictionary of keys provides a compact way to deduplicate hashable values in first-seen order.
A positional-only parameter lets a library change its internal argument name without breaking keyword callers. The slash marks the boundary.
Month length depends on both the month and the year. Ask the calendar rather than maintaining a table with a special February branch.
A dataclass defines the shape of a small record while generating routine initialization and representation methods.
A function signature can distinguish the item being processed from optional policies. A keyword-only flag makes call sites easier to read.
ISO week numbering has its own year boundary. A late-December calendar date can belong to week one of the next ISO year.
Hexadecimal represents each byte with two digits. It is a convenient inspection format for payloads that are awkward to print.
Chunk boundaries are easier to inspect when the final short chunk remains intact. Slices naturally stop at the end of the list.
Dictionary order reflects insertion history. Updating an existing key's value does not move it to the end.
Chaining iterables lets a consumer traverse several sources through one iterator. It does not need a combined intermediate list.
Path objects join segments according to filesystem rules. An absolute later segment can replace the earlier base.
A regular expression can describe a family of separators in one pass. Consecutive separators raise a separate question about empty fields.
A lazy merge can yield the next smallest item across sorted inputs. Its ordering guarantee depends on each input already being sorted.
Extended slice assignment edits selected positions in place. With a stride other than one, the replacement length must match the selected positions.