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
DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 29 May, 2026 · A deque stands for Double-Ended Queue. It is a type of data structure that allows to add and remove elements from both ends efficiently.
Published   May 29, 2026
Discussions

How are deques in Python implemented, and when are they worse than lists? - Stack Overflow
I've recently gotten into investigating how various data structures are implemented in Python in order to make my code more efficient. In investigating how lists and deques work, I found that I can... More on stackoverflow.com
🌐 stackoverflow.com
queue - How Does Deque Work in Python - Stack Overflow
I am having trouble understanding how the deque works in the snippet of code below, while trying to recreate a queue and a stack in Python. Stack Example - Understood stack = ["a", "b", "c"] # p... More on stackoverflow.com
🌐 stackoverflow.com
Python's deque is the stack object you want to use! I've written some tests to show the performance characteristics.
Very interesting! I tried your tests on python 3.3: for len=2 and iter = 1000000 list pop time = 0.8510 for len=2 and iter = 1000000 deque pop time = 0.8872 for len=2 and iter = 1000000 deque popL time = 0.88651 for len=2 and iter = 1000000 deque popH time = 0.8807 for len=200000 and iter = 10 list pop time =0.6307 for len=200000 and iter = 10 deque pop time = 0.5276 for len=200000 and iter = 10 deque popL time = 0.5227 for len=200000 and iter = 10 deque popH time = 0.5216 for len=1 and iter = 5000000 list pop time = 1.6248 for len=1 and iter = 5000000 deque pop time = 1.3945 for len=1 and iter = 5000000 deque popL time = 1.3138 for len=1 and iter = 5000000 deque popH time = 1.3117 for len=50000000 and iter = 1 : laptop froze ;D (times rounded to four digits) All tests run on a i3-3110M 2.4Ghz 4 Gig Ram edit:sorry copy pasted wrong line edit_n: added other runs and sys info More on reddit.com
🌐 r/Python
13
16
January 28, 2014
Double ended queue (deque). What is it used for?
I used it to store the snake in a snake game. Put a pixel on the front, remove one from the back, and away you go! More on reddit.com
🌐 r/learnpython
6
2
December 24, 2018
🌐
Dataquest
dataquest.io › home › blog › python deque function: a better choice for queues and 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.
🌐
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.
🌐
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.
🌐
Mathspp
mathspp.com › blog › python-deque-tutorial
Python deque tutorial | mathspp
January 18, 2024 - This tutorial teaches how to work with the Python data structure `collections.deque` and provides 7 example use cases.
Find elsewhere
Top answer
1 of 4
113

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
🌐
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.
🌐
Medium
medium.com › the-pythonworld › most-developers-dont-use-deques-python-s-hidden-super-fast-list-alternative-collections-deque-3ec5c91965b9
Most Developers Don’t Use Deques — Python’s Hidden Super-Fast List Alternative (collections.deque) | by mata | The Pythonworld | Medium
September 10, 2025 - Each time you do it, Python has to shift every element in memory one step forward. If you’re working with large datasets or performance-critical code, that overhead adds up quickly. That’s where collections.deque comes in — a double-ended queue optimized for fast appends and pops from both ends.
🌐
DEV Community
dev.to › kathanvakharia › python-s-collections-module-deque-5b7g
Python's Collections Module: deque - DEV Community
June 19, 2021 - Deque, short for Double Ended Queue It is a list-like container with fast appends and pops... Tagged with python, collections, codenewbie, deque.
🌐
Medium
khambud.medium.com › deque-data-structure-96640031d4b0
Deque Data Structure
May 21, 2023 - Pronounced as ‘deck’ , deque stands for doubled ended queue. I am going over this data structure as I found it to be so versatile. It can be used as both queue and stack and have many built-in operation in collections module of Python.
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.

🌐
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).
🌐
Reddit
reddit.com › r/python › python's deque is the stack object you want to use! i've written some tests to show the performance characteristics.
r/Python on Reddit: Python's deque is the stack object you want to use! I've written some tests to show the performance characteristics.
January 28, 2014 -

I have a performance critical application where using a bidirectional stack would be advantageous. Python's default list is often used as a general stack where append() and pop() methods are used to insert and retrieve data. Python's collections module includes an object known as 'deque' which acts as a bidirectional stack allowing append and pop methods on the 'right hand' side, mirroring behavior and methods of the default list, and on the left hand side.

This collection class lacks many of the nicer methods of list such as slice indexes, but in stack oriented applications, I had heard that this object has performance characteristics that are desirable. To verify these claims. I wrote some timing tests and I pasted the code here

My tests are written to be compatible with python 2.7 and 3.x, but I have only run in 2.7. Anybody who is willing to contribute a 3.x test would be my hero.

As it stands:

for len=2 and iter = 1000000 list  pop time = 2.528
for len=2 and iter = 1000000 deque pop time  = 2.085
for len=2 and iter = 1000000 deque popL time = 2.054
for len=2 and iter = 1000000 deque popH time = 1.963

for len=200000 and iter = 10 list  pop time  = 1.2103
for len=200000 and iter = 10 deque pop time  = 0.9893
for len=200000 and iter = 10 deque popL time = 1.0090
for len=200000 and iter = 10 deque popH time = 0.99811

for len=5000000 and iter = 1 list  pop time  = 3.1540
for len=5000000 and iter = 1 deque pop time  = 2.4654
for len=5000000 and iter = 1 deque popL time = 2.440
for len=5000000 and iter = 1 deque popH time = 2.4685

for len=50000000 and iter = 1 list  pop time  = 34.17
for len=50000000 and iter = 1 deque pop time  = 26.83
for len=50000000 and iter = 1 deque popL time = 28.66
for len=50000000 and iter = 1 deque popH time = 27.93

We can generally conclude, in python 2.7, that deques perform ~20% - 25% percent faster for both large and short stacks. This holds up a both extreme ends use cases.

edit: without going into too much detail, I'll say that I wrote a test where the lists are iterated 100 fold after creation. I found that for this read-heavy application, deques have a ~5-10 percent performance penalty.

Top answer
1 of 5
3
Very interesting! I tried your tests on python 3.3: for len=2 and iter = 1000000 list pop time = 0.8510 for len=2 and iter = 1000000 deque pop time = 0.8872 for len=2 and iter = 1000000 deque popL time = 0.88651 for len=2 and iter = 1000000 deque popH time = 0.8807 for len=200000 and iter = 10 list pop time =0.6307 for len=200000 and iter = 10 deque pop time = 0.5276 for len=200000 and iter = 10 deque popL time = 0.5227 for len=200000 and iter = 10 deque popH time = 0.5216 for len=1 and iter = 5000000 list pop time = 1.6248 for len=1 and iter = 5000000 deque pop time = 1.3945 for len=1 and iter = 5000000 deque popL time = 1.3138 for len=1 and iter = 5000000 deque popH time = 1.3117 for len=50000000 and iter = 1 : laptop froze ;D (times rounded to four digits) All tests run on a i3-3110M 2.4Ghz 4 Gig Ram edit:sorry copy pasted wrong line edit_n: added other runs and sys info
2 of 5
2
I ran these tests on python 3.3 first(to get a speed comparison on my computer) and then on pypy. python3: for len=2 and iter = 1000000 list pop = 1.5169918490000782 for len=2 and iter = 1000000 deque pop = 1.5199099809999552 for len=2 and iter = 1000000 deqye popL = 1.532282466000197 for len=2 and iter = 1000000 deqye popH = 1.5290258930001528 for len=200000 and iter = 10 list pop = 1.1989290989999972 for len=200000 and iter = 10 deque pop = 0.9543098980000195 for len=200000 and iter = 10 deqye popL = 0.9504460660000404 for len=200000 and iter = 10 deqye popH = 0.9577706459999717 for len=5000000 and iter = 1 list pop = 2.8640108509998754 for len=5000000 and iter = 1 deque pop = 2.2612638999999035 for len=5000000 and iter = 1 deqye popL = 2.295908997999959 for len=5000000 and iter = 1 deqye popH = 2.2972882859999117 for len=50000000 and iter = 1 list pop = 28.073518526000043 for len=50000000 and iter = 1 deque pop = 22.835268901000063 for len=50000000 and iter = 1 deqye popL = 23.013742399999956 for len=50000000 and iter = 1 deqye popH = 22.693501633000096 pypy: for len=2 and iter = 1000000 list pop = 0.186662197113 for len=2 and iter = 1000000 deque pop = 0.257698059082 for len=2 and iter = 1000000 deqye popL = 0.252062797546 for len=2 and iter = 1000000 deqye popH = 0.251337051392 for len=200000 and iter = 10 list pop = 0.200149059296 for len=200000 and iter = 10 deque pop = 0.0975501537323 for len=200000 and iter = 10 deqye popL = 0.089910030365 for len=200000 and iter = 10 deqye popH = 0.0978012084961 for len=5000000 and iter = 1 list pop = 0.46339392662 for len=5000000 and iter = 1 deque pop = 0.223926067352 for len=5000000 and iter = 1 deqye popL = 0.24724817276 for len=5000000 and iter = 1 deqye popH = 0.212069988251 for len=50000000 and iter = 1 list pop = 3.75739717484 for len=50000000 and iter = 1 deque pop = 2.53583884239 for len=50000000 and iter = 1 deqye popL = 2.48548698425 for len=50000000 and iter = 1 deqye popH = 2.52400302887
🌐
Codecademy
codecademy.com › docs › python › deque › .popleft()
Python | Deque | .popleft() | Codecademy
October 23, 2025 - A deque (double-ended queue) allows elements to be added or removed efficiently from both ends. Calling .popleft() on an empty deque raises an IndexError. ... Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand ...
🌐
Reddit
reddit.com › r/learnpython › double ended queue (deque). what is it used for?
r/learnpython on Reddit: Double ended queue (deque). What is it used for?
December 24, 2018 -

Hi all. I recently got stumped on an advent of code challenge, as my naive list-based solution was just not solving due to time-complexity issues. I looked on the subreddit and someone had outlined a solution using a deque. I read up a bit on the idea and the architecture, but I can't find much information about practical uses, other than when you have elements in a "circular" type list.

Anyone have a good explanation or link to a good resource explaining when it would be good to use these? They seem like a really useful tool!

🌐
Medium
medium.com › @codingcampus › deque-in-python-34a02ad0e498
Deque in Python. A Deque is a data structure in the… | by CodingCampus | Medium
November 23, 2023 - A Deque is a data structure in the Python collection module that allows fast append and pop operations. In programming, we tend to deal with high volumes of data, and data structures are necessary to store that data.
🌐
Medium
medium.com › @pranaygore › deque-collections-in-python-8d9050297881
deque(collections) in Python. Deque is a double-ended abstract data… | by Pranay Gore | Medium
March 23, 2019 - deque(collections) in Python Deque is a double-ended abstract data type object which supports appending and poping items in an efficient way. It is a double ended queue. We can look at it as a …
🌐
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 ...
🌐
FavTutor
favtutor.com › blogs › deque-python
Python Deque: Example, Implementation & Methods (with code)
March 15, 2023 - At this point, you should have a complete grasp of the deque in python with different methods. Python's deque is a low-level and highly streamlined double-ended queue that can be used to build them in a sleek, efficient, and Pythonic way.