https://github.com/python/cpython/blob/v3.8.1/Modules/_collectionsmodule.c

A dequeobject is composed of a doubly-linked list of block nodes.

So yes, a deque is a (doubly-)linked list as another answer suggests.

Elaborating: What this means is that Python lists are much better for random-access and fixed-length operations, including slicing, while deques are much more useful for pushing and popping things off the ends, with indexing (but not slicing, interestingly) being possible but slower than with lists.

Answer from JAB on Stack Overflow
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ collections.html
collections โ€” Container datatypes
Deques are a generalization of stacks and queues (the name is pronounced โ€œdeckโ€ and is short for โ€œdouble-ended queueโ€).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ deque-in-python
Deque in Python - GeeksforGeeks
A deque stands for Double-Ended Queue. It is a special type of data structure that allows to add and remove elements from both ends efficiently.
Published ย  December 11, 2025
๐ŸŒ
Real Python
realpython.com โ€บ python-deque
Python's deque: Implement Efficient Queues and Stacks โ€“ Real Python
January 12, 2026 - This data type was specially designed to overcome the efficiency problems of .append() and .pop() in Python lists. A deque is a sequence-like data structure designed as a generalization of stacks and queues.
๐ŸŒ
Dataquest
dataquest.io โ€บ blog โ€บ python-deque-queues-stacks
Python Deque Function: A Better Choice for Queues and Stacks โ€“ Dataquest
April 7, 2025 - If you use Python, you're probably familiar with lists, and you probably use them a lot, too. They're great data structures with many helpful methods that allow the user to modify the list by adding, removing, and sorting items. However, there are some use cases when a list may look like a great choice, but it just isn't. That is where the deque() function (short for double-ended queue, pronounced like "deck") from the collections module can be a much better choice when you need to implement queues and stacks in Python.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ deque
Python | Deque | Codecademy
April 10, 2025 - A deque is a double-ended queue implementation in Pythonโ€™s collections module. It provides a versatile data structure that generalizes a stack and a queue by allowing efficient append and pop operations from both ends of the sequence.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ advanced-built-in-data-structures-and-their-usage โ€บ lessons โ€บ understanding-queues-and-deques-in-python
Understanding Queues and Deques in Python
A deque, or "double-ended queue", allows the addition and removal of items from both ends. Python provides the collections module containing the deque class for implementing deques.
Top answer
1 of 4
111

https://github.com/python/cpython/blob/v3.8.1/Modules/_collectionsmodule.c

A dequeobject is composed of a doubly-linked list of block nodes.

So yes, a deque is a (doubly-)linked list as another answer suggests.

Elaborating: What this means is that Python lists are much better for random-access and fixed-length operations, including slicing, while deques are much more useful for pushing and popping things off the ends, with indexing (but not slicing, interestingly) being possible but slower than with lists.

2 of 4
62

Check out collections.deque. From the docs:

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.

Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.

Just as it says, using pop(0) or insert(0, v) incur large penalties with list objects. You can't use slice/index operations on a deque, but you can use popleft/appendleft, which are operations deque is optimized for. Here is a simple benchmark to demonstrate this:

import time
from collections import deque

num = 100000

def append(c):
    for i in range(num):
        c.append(i)

def appendleft(c):
    if isinstance(c, deque):
        for i in range(num):
            c.appendleft(i)
    else:
        for i in range(num):
            c.insert(0, i)
def pop(c):
    for i in range(num):
        c.pop()

def popleft(c):
    if isinstance(c, deque):
        for i in range(num):
            c.popleft()
    else:
        for i in range(num):
            c.pop(0)

for container in [deque, list]:
    for operation in [append, appendleft, pop, popleft]:
        c = container(range(num))
        start = time.time()
        operation(c)
        elapsed = time.time() - start
        print "Completed %s/%s in %.2f seconds: %.1f ops/sec" % (container.__name__, operation.__name__, elapsed, num / elapsed)

Results on my machine:

Completed deque/append in 0.02 seconds: 5582877.2 ops/sec
Completed deque/appendleft in 0.02 seconds: 6406549.7 ops/sec
Completed deque/pop in 0.01 seconds: 7146417.7 ops/sec
Completed deque/popleft in 0.01 seconds: 7271174.0 ops/sec
Completed list/append in 0.01 seconds: 6761407.6 ops/sec
Completed list/appendleft in 16.55 seconds: 6042.7 ops/sec
Completed list/pop in 0.02 seconds: 4394057.9 ops/sec
Completed list/popleft in 3.23 seconds: 30983.3 ops/sec
๐ŸŒ
Mathspp
mathspp.com โ€บ blog โ€บ python-deque-tutorial
Python deque tutorial | mathspp
This tutorial teaches how to work with the Python data structure `collections.deque` and provides 7 example use cases.
Find elsewhere
๐ŸŒ
Allendowney
allendowney.github.io โ€บ DSIRP โ€บ deque.html
Deque โ€” Data Structures and Information Retrieval in Python
Fortunately, there are ways to implement lists that can add and remove elements from both ends in constant time. A collection that has this property is called a double-ended queue, abbreviated โ€œdequeโ€ and pronounced like โ€œdeckโ€.
Top answer
1 of 2
23

A deque is a generalization of stack and a queue (It is short for "double-ended queue").

Thus, the pop() operation still causes it to act like a stack, just as it would have as a list. To make it act like a queue, use the popleft() command. Deques are made to support both behaviors, and this way the pop() function is consistent across data structures. In order to make the deque act like a queue, you must use the functions that correspond to queues. So, replace pop() with popleft() in your second example, and you should see the FIFO behavior that you expect.

Deques also support a max length, which means when you add objects to the deque greater than the maxlength, it will "drop" a number of objects off the opposite end to maintain its max size.

2 of 2
3

I'll add my two cents as I was searching for this exact question but more from the time complexity involved and what should be the preferred choice for a queue implementation in Python.

As per the docs:

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.

This means you can use dequeues as a stack(Last in First out) and queue(First in First out) implementation with pop() or popleft() operation in O(1).

Again from docs

Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.

However, using the list as a queue requires popping from the 0th index which will cause data to be shifted resulting in O(N) operation. So if you want to use a queue for a time sensitive operation (production code or competitive programming) always use dequeue for queue implementation.

๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
How to Use Deque in Python: collections.deque | note.nkmk.me
April 20, 2025 - In Python, the collections.deque class provides an efficient way to handle data as a queue, stack, or deque (double-ended queue). collections - deque objects โ€” Container datatypes โ€” Python 3.13.3 do ...
๐ŸŒ
DEV Community
dev.to โ€บ v_it_aly โ€บ python-deque-vs-listwh-25i9
Python: deque vs. list - DEV Community
December 10, 2020 - Internally, deque is a representation of a doubly-linked list. Doubly-linked means that it stores at least two more integers (pointers) with each item, which is why such lists take up more memory space. In contrast, lists in Python are implemented with fixed size memory blocks (arrays) and hence, they use less memory space than deques, but lists have to reallocate memory when a new item is inserted (except when appending).
๐ŸŒ
Python Module of the Week
pymotw.com โ€บ 2 โ€บ collections โ€บ deque.html
Deque - Python Module of the Week
Since deques are a type of sequence container, they support some of the same operations that lists support, such as examining the contents with __getitem__(), determining length, and removing elements from the middle by matching identity. $ python collections_deque.py Deque: deque(['a', 'b', 'c', 'd', 'e', 'f', 'g']) Length: 7 Left end: a Right end: g remove(c): deque(['a', 'b', 'd', 'e', 'f', 'g'])
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_deque.htm
Python - Deque
A double-ended queue, or deque, has the feature of adding and removing elements from either end. The Deque module is a part of collections library. It has the methods for adding and removing elements which can be invoked directly with arguments.
๐ŸŒ
Zero To Mastery
zerotomastery.io โ€บ blog โ€บ python-deque
Beginnerโ€™s Guide to Python Deque | Zero To Mastery
November 3, 2025 - deque (short for double-ended queue) changes how Python manages data behind the scenes.
๐ŸŒ
Pythontic
pythontic.com โ€บ containers โ€บ deque โ€บ introduction
The deque in Python | Pythontic.com
The deque is a container class in Python which can hold a collection of Python objects.
๐ŸŒ
CodingNomads
codingnomads.com โ€บ python-deque-for-python-queue-and-stack
Python Deque for Python Queue and Stack
So, what should you do if you want to ensure constant time for insertion and deletion in one of your programs? Python's got you covered! In this lesson, you'll use collections.deque to model both stacks and queues. The abbreviation stands for "double-ended queue.
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ pythonds โ€บ BasicDS โ€บ ImplementingaDequeinPython.html
4.17. Implementing a Deque in Python โ€” Problem Solving with Algorithms and Data Structures
1class Deque: 2 def __init__(self): 3 self.items = [] 4 5 def isEmpty(self): 6 return self.items == [] 7 8 def addFront(self, item): 9 self.items.append(item) 10 11 def addRear(self, item): 12 self.items.insert(0,item) 13 14 def removeFront(self): 15 return self.items.pop() 16 17 def removeRear(self): 18 return self.items.pop(0) 19 20 def size(self): 21 return len(self.items)
๐ŸŒ
Hackr
hackr.io โ€บ home โ€บ articles โ€บ programming
How to Use a Python Deque for Fast and Efficient Queues
January 30, 2025 - Python Deque is a fast and efficient double-ended queue data structure that supports adding and removing elements from either end of a queue.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-use-a-deque-in-python
How to use a deque in Python
A deque is a double-ended queue in which elements can be both inserted and deleted from either the left or the right end of the queue. An implementation of a deque in Python is available in the collections module.