← index #5244Issue #847
Off-topic · high · value 1.393
QUERY · ISSUE

collections.deque constructor does not take keyword arguments

openby nevercastopened 2019-10-21updated 2019-11-15
enhancementpy-core

I would like to construct a deque as follows collections.deque(maxlen=10). For this to work, iterables must have a default. The default should be an empty tuple or None, see: https://docs.python.org/3/library/collections.html#collections.deque

maxlen should also support keyword arguments but would not require a default, i.e not optional, since I don't need arbitrarily (unbounded) length deques.

CANDIDATE · ISSUE

Deque is not a deque

closedby Kacarottopened 2024-04-15updated 2024-04-16

A deque, as described in the docs, is:

Deques (double-ended queues) are a list-like container that support O(1) appends and pops from either side of the deque.

And yet the implementation seems to very clearly be just a list, calling itself a deque? And just like a list it has O(N) appends and pops from the left:

class deque:
    def __init__(self, iterable=None):
        if iterable is None:
            self.q = []
        else:
            self.q = list(iterable)

    def popleft(self):
        return self.q.pop(0)

    ...

    def appendleft(self, a):
        self.q.insert(0, a)
2 comments
andrewleech · 2024-04-15

This older library was made for simple / basic API compatibility with a minimal subset of the cpython library api.

The faster C built-in version was recently expanded in master for the next release of micropython which should render this library obsolete.
https://github.com/micropython/micropython/pull/10724

mattytrentini · 2024-04-16

I've raised #848 to remove that now-unnecessary deque implementation.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied