Reductions and statistics
Reduce a finite sample to a total or a statistic suited to the question.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Reduce a finite sample to a total or a statistic suited to the question.
A pattern describes text structure and fullmatch requires the entire string to match.
Scope determines where a name can be resolved, while references can keep an object alive beyond a function call.
At an input boundary, bound the size before parsing and validate the resulting value against application rules.
Sort records by a key that is computed once per input element.
A str is an immutable sequence of Unicode code points, while bytes hold encoded octets.
A test compares observed behavior to an expectation, including values on either side of a boundary.
Represent calendar dates separately from instants with a UTC offset and durations with timedelta.
A type constructor converts a value according to its own rules and raises an exception for unsupported input.
Every object has a type that determines its operations, while a parameter annotation imposes no automatic runtime type check.
An annotation can describe the interface a static checker expects without requiring a shared base class.
Assignment to a name binds it to the right-hand object without copying that object.
The three-dot literal denotes the singleton Ellipsis, which can be recognized by identity.
NotImplemented is a singleton that an operator method can return to decline an operand pairing.
Inspect the handlers attached directly to a logger, attach a configured handler with `addHandler()`, and empty the list through `removeHandler()` rather than editing it directly.
In a function definition, `*args` collects extra positional arguments and `**kwargs` collects extra keyword arguments. In a call, the same star syntax unpacks values instead.
In a function definition, `*args` collects leftover positional arguments into a tuple. In the call `fn(*args)`, the star does the reverse: it passes the tuple’s items as separate positional arguments.
Use `assertEqual` to compare actual and expected values, prepare test data with `setUp`, and cover multiple inputs and exceptions in `unittest`.
Use `unittest.TestCase.assertRaises` in callable form or in a `with` block to check that an operation raises the expected exception.
Request cancellation, wait for the task to finish, then report its name and whether it was actually cancelled.
`collections.deque.append` adds one item to the right end of a double-ended queue. In this sliding-window example, the monotonic queue stores indices rather than the values themselves.
`deque.pop()` removes and returns the rightmost item of a double-ended queue. Use it to discard dominated candidates when computing a sliding-window maximum.
`popleft()` removes and returns the first item in a deque. In a sliding window, it lets you discard indices that fall before the window’s left boundary.
Parse date text with `strptime()`, extract the calendar date with `.date()`, and pair it with a separate time using `datetime.combine()`.