maxlen

An optional deque setting that caps its length; once full, adding at one end silently drops an item from the other end.

In more detail

deque(maxlen=3) always holds the three most recent items, which is exactly a sliding window. It behaves like a ring buffer without your having to manage indices. Use it for "last k events" or moving statistics in application code.

Example

window = deque(maxlen=3)

Related terms

Taught in

References