deque.popleft() is faster than list.pop(0), because the deque has been optimized to do popleft() approximately in O(1), while list.pop(0) takes O(n) (see deque objects).

Comments and code in _collectionsmodule.c for deque and listobject.c for list provide implementation insights to explain the performance differences. Namely that a deque object "is composed of a doubly-linked list", which effectively optimizes appends and pops at both ends, while list objects are not even singly-linked lists but C arrays (of pointers to elements (see Python 2.7 listobject.h#l22 and Python 3.5 listobject.h#l23), which makes them good for fast random access of elements but requires O(n) time to reposition all elements after removal of the first.

For Python 2.7 and 3.5, the URLs of these source code files are:

  1. https://hg.python.org/cpython/file/2.7/Modules/_collectionsmodule.c

  2. https://hg.python.org/cpython/file/2.7/Objects/listobject.c

  3. https://hg.python.org/cpython/file/3.5/Modules/_collectionsmodule.c

  4. https://hg.python.org/cpython/file/3.5/Objects/listobject.c

Using %timeit, the performance difference between deque.popleft() and list.pop(0) is about a factor of 4 when both the deque and the list have the same 52 elements and grows to over a factor of 1000 when their lengths are 10**8. Test results are given below.

import string
from collections import deque

%timeit d = deque(string.letters); d.popleft()
1000000 loops, best of 3: 1.46 ยตs per loop

%timeit d = deque(string.letters)
1000000 loops, best of 3: 1.4 ยตs per loop

%timeit l = list(string.letters); l.pop(0)
1000000 loops, best of 3: 1.47 ยตs per loop

%timeit l = list(string.letters);
1000000 loops, best of 3: 1.22 ยตs per loop

d = deque(range(100000000))

%timeit d.popleft()
10000000 loops, best of 3: 90.5 ns per loop

l = range(100000000)

%timeit l.pop(0)
10 loops, best of 3: 93.4 ms per loop
Answer from user4322779 on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ deque-in-python
Deque in Python - GeeksforGeeks
It can function as both a queue (FIFO) and a stack (LIFO). Ideal for scheduling, sliding window problems and real-time data processing. It offers powerful built-in methods like appendleft(), popleft() and rotate().
Published ย  December 11, 2025
๐ŸŒ
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 programming languages today.
๐ŸŒ
Real Python
realpython.com โ€บ python-deque
Python's deque: Implement Efficient Queues and Stacks โ€“ Real Python
January 12, 2026 - To enqueue a person, you use .append(), which adds individual items to the right end. To dequeue a person, you use .popleft(), which removes and returns the item at the left end of a deque.
Top answer
1 of 3
72

deque.popleft() is faster than list.pop(0), because the deque has been optimized to do popleft() approximately in O(1), while list.pop(0) takes O(n) (see deque objects).

Comments and code in _collectionsmodule.c for deque and listobject.c for list provide implementation insights to explain the performance differences. Namely that a deque object "is composed of a doubly-linked list", which effectively optimizes appends and pops at both ends, while list objects are not even singly-linked lists but C arrays (of pointers to elements (see Python 2.7 listobject.h#l22 and Python 3.5 listobject.h#l23), which makes them good for fast random access of elements but requires O(n) time to reposition all elements after removal of the first.

For Python 2.7 and 3.5, the URLs of these source code files are:

  1. https://hg.python.org/cpython/file/2.7/Modules/_collectionsmodule.c

  2. https://hg.python.org/cpython/file/2.7/Objects/listobject.c

  3. https://hg.python.org/cpython/file/3.5/Modules/_collectionsmodule.c

  4. https://hg.python.org/cpython/file/3.5/Objects/listobject.c

Using %timeit, the performance difference between deque.popleft() and list.pop(0) is about a factor of 4 when both the deque and the list have the same 52 elements and grows to over a factor of 1000 when their lengths are 10**8. Test results are given below.

import string
from collections import deque

%timeit d = deque(string.letters); d.popleft()
1000000 loops, best of 3: 1.46 ยตs per loop

%timeit d = deque(string.letters)
1000000 loops, best of 3: 1.4 ยตs per loop

%timeit l = list(string.letters); l.pop(0)
1000000 loops, best of 3: 1.47 ยตs per loop

%timeit l = list(string.letters);
1000000 loops, best of 3: 1.22 ยตs per loop

d = deque(range(100000000))

%timeit d.popleft()
10000000 loops, best of 3: 90.5 ns per loop

l = range(100000000)

%timeit l.pop(0)
10 loops, best of 3: 93.4 ms per loop
2 of 3
28

Is there performance difference?

Yes. deque.popleft() is O(1) -- a constant time operation. While list.pop(0) is O(n) -- linear time operation: the larger the list the longer it takes.

Why?

CPython list implementation is array-based. pop(0) removes the first item from the list and it requires to shift left len(lst) - 1 items to fill the gap.

deque() implementation uses a doubly linked list. No matter how large the deque, deque.popleft() requires a constant (limited above) number of operations.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ queue-in-python
Queue in Python - GeeksforGeeks
December 11, 2025 - Explanation: popleft() efficiently removes the first element without shifting, making deque ideal for queues. Pythonโ€™s queue module provides a thread-safe FIFO queue. You can specify a maxsize.
๐ŸŒ
Pythontic
pythontic.com โ€บ containers โ€บ deque โ€บ popleft
The popleft() method of deque class | Pythontic.com
A deque Python is double ended queue. Elements can be added and removed from either side of the deque. The popleft() method removes an element from the left side of the deque and returns the element.
๐ŸŒ
Dataquest
dataquest.io โ€บ blog โ€บ python-deque-queues-stacks
Python Deque Function: A Better Choice for Queues and Stacks โ€“ Dataquest
April 7, 2025 - This function won't actually play a song since the goal is just to make a representation of queue functioning in Python. Instead, this function takes in a queue, deletes the leftmost element, and prints the deleted item and the current queue.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @mollihua โ€บ pop-first-element-of-a-queue-in-python-list-pop-0-vs-collections-deque-popleft-7991408e45b
Pop first element of a queue in Python โ€” list.pop(0) vs deque.popleft() | by mollihua | Medium
July 2, 2020 - def listpop(alist): ts = time.time() alist.pop(0) te = time.time() print("{:e}".format(te - ts))def dequepopleft(alist): q = collections.deque(alist) ts = time.time() q.popleft() te = time.time() print("{:e} seconds".format(te - ts))a = [x for x in range(10**6)]listpop(a) # output: 4.558802e-03 seconds dequepopleft(a) # output: 2.861023e-06 seconds ยท Python ยท Queue ยท
๐ŸŒ
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 ...
We begin by creating an empty Queue, for which we can use Python's built-in deque. We can add or enqueue elements to the end of the Queue using the append() method. Similarly, the removal or dequeue of an element from the start of the Queue can be done using the popleft() method.
๐ŸŒ
CodingNomads
codingnomads.com โ€บ python-deque-for-python-queue-and-stack
Python Deque for Python Queue and Stack
If you look at the Python documentation for the class, you'll see that you can add and remove items from both ends of the collection. That makes it possible to use deque also as a queue: from collections import deque queue = deque() queue.append(1) queue.append(2) queue.append(3) print(queue) # deque([1, 2, 3]) queue.popleft() # 1 queue.popleft() # 2 queue.popleft() # 3 print(queue) # deque([]) queue.popleft() # IndexError: pop from an empty deque
๐ŸŒ
Medium
medium.com โ€บ analytics-vidhya โ€บ a-brief-overview-of-queue-in-python-7e9ea57a47e4
A brief overview of Queue in Python | by Nilson Chapagain | Analytics Vidhya | Medium
August 8, 2021 - from collections import deque class Queue(): def __init__(self): self.queue = deque() self.size = 0 def enqueue(self, item): self.queue.append(item) self.size += 1 def dequeue(self, item): if self.size > 0: self.size -= 1 return self.queue.popleft() else: return None def peek(self): if self.size > 0: ret_val = self.queue.popleft() self.queue.appendleft(ret_val) return ret_val else: return None def get_size(self): return self.size def __str__(self): queue_items = [] if self.size > 0: counter=0 while self.size > counter: val = self.queue.popleft() queue_items.append(val) counter+=1 while counter>0: self.queue.appendleft(queue_items[counter-1]) counter-=1 return str(queue_items) else: return None ยท
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ queue.html
queue โ€” A synchronized queue class
February 23, 2026 - collections.deque is an alternative implementation of unbounded queues with fast atomic append() and popleft() operations that do not require locking and also support indexing.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ deque-in-python
Deque in Python
June 26, 2020 - Like appending, there are two different types of pop functions. The pop() method is used to remove and return the right most element from the queue, and popleft() method is used to remove and return left most element from the queue.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.4 documentation
>>> from collections import deque >>> queue = deque(["Eric", "John", "Michael"]) >>> queue.append("Terry") # Terry arrives >>> queue.append("Graham") # Graham arrives >>> queue.popleft() # The first to arrive now leaves 'Eric' >>> queue.popleft() # The second to arrive now leaves 'John' >>> queue # Remaining queue in order of arrival deque(['Michael', 'Terry', 'Graham'])
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
How to Use Deque in Python: collections.deque | note.nkmk.me
April 20, 2025 - To use deque as a queue, add elements with append() and remove them with popleft().
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ collections.html
collections โ€” Container datatypes
When the deque is not empty, rotating one step to the right is equivalent to d.appendleft(d.pop()), and rotating one step to the left is equivalent to d.append(d.popleft()).
๐ŸŒ
Python.org
discuss.python.org โ€บ ideas
Deque.append() should return popped item - Ideas - Discussions on Python.org
November 19, 2024 - If a deque is used with a fixed size, appending to one end will pop from the other end. However, thereโ€™s currently no way to reference this popped item. If I want to use it as a FIFO, I need to make sure that I pop from the right direction ...
๐ŸŒ
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 - We then enqueue elements โ€˜Aโ€™, โ€˜Bโ€™, and โ€˜Cโ€™ using the append() method. Finally, we dequeue elements using the popleft() method, which removes and returns an element from the left end of the deque.