Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deque is not a deque #847

Closed
Kacarott opened this issue Apr 15, 2024 · 2 comments
Closed

Deque is not a deque #847

Kacarott opened this issue Apr 15, 2024 · 2 comments

Comments

@Kacarott
Copy link

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)
@andrewleech
Copy link
Sponsor Contributor

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.
micropython/micropython#10724

@mattytrentini
Copy link
Sponsor Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants