`deque.pop()` — remove the rightmost item
`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.
CKTIS / Python
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
`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()`.
Register context managers at runtime, then call `stack.close()` to release their resources in reverse registration order before the enclosing `with` block ends.
Use `ExitStack.enter_context()` when you decide at runtime which contexts to enter. Get each entry value back and clean up in reverse registration order.
Call `disable()` on the same `cProfile.Profile` instance to stop collecting data before analysis without discarding the statistics already gathered.
Start collecting data just before calling `run_profiled()`, stop in `finally`, and then inspect the results so setup and analysis stay outside the profile.
In Python 3.12, `strptime()` returns a `datetime`, `.date()` extracts the calendar date, and `combine()` pairs it with a chosen time.
Attach a known fixed UTC offset without changing the calendar date or clock reading, then format the result as either a custom string or an ISO 8601 string.
`strptime()` reads text using a supplied format and returns a `datetime`. Use `.date()` to extract the calendar date and `combine()` to pair it with a separate time.
Merge defaults and overrides into a new dictionary. When both inputs contain the same key, the value from the right wins.
Use `tuple[T, ...]` for a tuple of any length, including zero, whose elements must all be compatible with `T`.
In Python 3.12, `...` is a literal for the `Ellipsis` object. In a protocol method body it signals that no implementation is supplied, but it does not return that object.
In Python 3.12, `...` denotes the `Ellipsis` object. A bare `...` can signal an omitted implementation, but `@abstractmethod`, not `...`, marks the method as abstract.
In Python 3.12, use `LoggerAdapter.error()` to log at `ERROR` level with a `team` field you don’t have to pass on each call.
Run a test suite and use the returned result to count test cases started, assertion failures, and unexpected exceptions separately.
Run a test suite and use `testsRun`, `failures`, and `errors` to build a deterministic summary without parsing the runner’s text report.
In Python 3.12, a quoted type annotation can refer to a name that becomes available only after the function is defined.
In Python 3.12, quote a type name that is not yet available when a method is defined, then resolve the reference later if you need the class object.
Read a function's documentation without calling it, and preserve its name and docstring across decoration so audit logs and reports describe the intended function.
Call `cache_info()` on a decorated function to see its cumulative hits and misses, its configured cache limit, and how many entries it currently holds.
`get_name()` returns an asyncio task’s current name as a string. Use it to label a report, and check `cancelled()` separately to tell whether the task was actually cancelled.
Use `read()` to consume text from the current position, `write()` to build output in pieces, and `getvalue()` to retrieve all the text without moving the position.
Read from the current position in a `StringIO` text stream, and distinguish that operation from retrieving the entire buffer with `getvalue()`.