deque are implemented a little smarter than just doubly-linked lists. They're a doubly-linked list of blocks of Python objects, where the left and right sides may be incomplete blocks.

The Big-O cost of accessing in the middle is still O(n), but it has a constant divisor (implementation dependent, CPython 3.5 allocates blocks that can store 64 objects). So if your deque has 1000 members, accessing in the middle still involves only around 7-8 "linked list-style" traversals, not 500-some. If the deque is smallish (65 to 128 elements, depending on how the empty slots align with the head and tail blocks), then lookup of any element is equal cost.

Answer from ShadowRanger on Stack Overflow
🌐
Python
wiki.python.org › moin › TimeComplexity
TimeComplexity - Python Wiki
A deque (double-ended queue) is represented internally as a doubly linked list. (Well, a list of arrays rather than objects, for greater efficiency.) Both ends are accessible, but even looking at the middle is slow, and adding to or removing from the middle is slower still. See dict -- the implementation is intentionally very similar. As seen in the source code the complexities for set difference s-t or s.difference(t) (set_difference()) and in-place set difference s.difference_update(t) (set_difference_update_internal()) are different!
🌐
Real Python
realpython.com › python-deque
Python's deque: Implement Efficient Queues and Stacks – Real Python
January 12, 2026 - This process takes longer to complete, and the append operation passes from being O(1) to O(n). Consider the following performance tests for appending items to the left end of a sequence, deque vs list: ... from collections import deque from ...
🌐
DEV Community
dev.to › wnleao › python-deque-vs-list-time-comparison-5ch4
Python deque vs list: a time comparison - DEV Community
April 10, 2022 - Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”). Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction. In python, list operations pop from the end and append will also have time complexity O(1).
🌐
Note.nkmk.me
note.nkmk.me › home › python
How to Use Deque in Python: collections.deque | note.nkmk.me
April 20, 2025 - However, in deque, methods like append(), appendleft(), pop(), and popleft() for adding and removing the first and last elements all have O(1) time complexity. This is also mentioned in the official documentation.
🌐
GeeksforGeeks
geeksforgeeks.org › python › deque-implementation-in-python
Deque Implementation in Python - GeeksforGeeks
July 23, 2025 - Python lists can be used to simulate a deque, but since lists are dynamic arrays, operations at the beginning of the list are inefficient because elements need to be shifted. Below are the basic operations: ... 1. Append at the rear (list.append(item) → O(1) ): This operation adds an item to the end (rear) of the list. Time Complexity is O(1).
🌐
Python Morsels
pythonmorsels.com › time-complexities
Python Big O: the time complexities of different data structures in Python - Python Morsels
April 16, 2024 - For inexpensive operations involving ... collections.deque data structure is for. >>> from collections import deque >>> queue = deque([2, 1, 3, 4]) Here are the time complexities of common ......
Find elsewhere
🌐
Pythoncomplexity
pythoncomplexity.com › stdlib › deque
Deque - Python Big-O: Time & Space Complexity
from collections import deque import time # List - O(n) popleft (must shift all elements) lst = list(range(1000000)) start = time.time() for _ in range(1000): lst.pop(0) # O(n) list_time = time.time() - start # Deque - O(1) popleft dq = deque(range(1000000)) start = time.time() for _ in range(1000): dq.popleft() # O(1) deque_time = time.time() - start # deque is much faster for queue operations
🌐
TutorialsPoint
tutorialspoint.com › deque-in-python
Deque in Python
June 26, 2020 - The Deque is basically a generalization of stack and queue structure, where it is initialized from left to right. It uses the list object to create a deque.It provides O(1) time complexity for popping and appending.
🌐
Codecademy
codecademy.com › docs › python › deque
Python | Deque | Codecademy
April 10, 2025 - Deques have O(1) time complexity for append and pop operations at both ends, while lists have O(n) time complexity for operations at the beginning. For operations at the end, both have similar performance.
🌐
Python Central
pythoncentral.io › understanding-pythons-deque
Understanding Python's deque | Python Central
February 11, 2025 - For example, in a real-time system processing tasks, you could use appendleft to add high-priority tasks and append for normal priority tasks, while using pop/popleft to process them accordingly.
🌐
GeeksforGeeks
geeksforgeeks.org › deque-in-python
Deque in Python - GeeksforGeeks
Here’s a table listing built-in operations of a deque in Python with descriptions and their corresponding time complexities:
Published   March 6, 2025
🌐
ZetCode
zetcode.com › python › deque
Python deque - Complete Guide
April 2, 2025 - A deque (pronounced "deck") is a double-ended queue from Python's collections module that supports efficient append and pop operations from both ends. It provides O(1) time complexity for these operations compared to O(n) for lists. This guide covers deque creation, operations, performance ...
🌐
iO Flood
ioflood.com › blog › using-deque-in-python-python-queues-and-stacks-made-easy
Using Deque in Python | Python Queues and Stacks Guide
March 12, 2024 - Deque is a Python function for efficient data handling. It’s more versatile than lists, especially for implementing queues and stacks. It allows efficient append and pop operations from both ends with a time complexity of O(1). It’s also thread-safe, making it a safer choice for multithreaded ...
🌐
OpenGenus
iq.opengenus.org › deque-python
Deque in Python
March 20, 2020 - To begin using Deque in your python program use the code given below. import collections de = collections.deque([1,2,3]) Deque requires O(1) time to perform the operations of append and pop. Whereas, a list requires O(N) complexity. For reference a machine takes 1s to perform 10^6 operations.
🌐
CodeSignal
codesignal.com › learn › courses › linked-lists-stacks-and-queues-in-python › lessons › understanding-and-implementing-queues-exploring-core-concepts-python-implementation-and-time-complexity
Understanding and Implementing Queues: Exploring Core ...
In order to make smart decisions about data structures, it's important to be mindful of their time and space complexities. In the case of a Queue implemented using the collections.deque, the time complexity for both the enqueue (adding an element at the end of the Queue) and dequeue (removing ...
🌐
Scribd
scribd.com › document › 756791080 › Deque-in-Python
Python Deque Operations Explained | PDF | Queue (Abstract Data Type) | Computer Programming
Deque (Doubly Ended Queue) in Python ... operations from both the ends of the container, as deque provides an O(1) time complexity for append and pop operations as compared to a list that provides O(n) time complexity....