Collection Classes

collections.deque()

Build a double-ended queue supporting efficient operations at either end. A bounded deque discards from the opposite end on append when full.

Formal Syntax & Structure

python syntaxpython
collections.deque(iterable=(), maxlen=None)

Parameters & Attributes

NameTypeDescription
iterableiterableInput values, consumed as needed.
maxlenint or NoneMaximum deque length, or None for unbounded.

Return Value

deque

The deque result described above.

Working Example

Example Snippetpython
import collectionsprint(list(collections.deque([1,2,3],maxlen=2)))
Python Reference