Parameter | Details |
---|---|
iterable | Creates the deque with initial elements copied from another iterable. |
maxlen | Limits how large the deque can be, pushing out old elements as new are added. |
This class is useful when you need an object similar to a list that allows fast append and pop operations from either side (the name deque
stands for “double-ended queue”).
The methods provided are indeed very similar, except that some like pop
, append
, or extend
can be suffixed with left
. The deque
data structure should be preferred to a list if one needs to frequently insert and delete elements at both ends because it allows to do so in constant time O(1).