🌐
GeeksforGeeks
geeksforgeeks.org › python › 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   1 week ago
🌐
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 ...
Discussions

Use deque instead of list always ?

The article mentions the advantages of deque, but neglects the mention its disadvantages. While deque has fast pop/append from both ends, it has slow item access.

Use deque only if you need insert/remove to be fast from both ends, and don't care about read speeds. List has constant time append/pop from one end and also constant time access anywhere in the list. You should almost always prefer list over deque, which is why list is builtin.

More on reddit.com
🌐 r/learnpython
8
13
December 28, 2017
What is Deque in Python ?
Good to know !!! More on reddit.com
🌐 r/Python
5
0
May 1, 2019
Can someone help me with this old question 'Python – Reading last N lines of a file (for example a log file'?
I suspect you can find some alternative answers here More on reddit.com
🌐 r/PythonLearning
5
2
September 24, 2024
Python avoid deque import
Ig pop(0) from a list has O(n) time complexity whereas in deque it's O(1) approx More on reddit.com
🌐 r/leetcode
9
0
April 19, 2024
🌐
Python
docs.python.org › 3 › library › collections.html
collections — Container datatypes
Starting in version 3.5, deques support __add__(), __mul__(), and __imul__(). ... >>> from collections import deque >>> d = deque('ghi') # make a new deque with three items >>> for elem in d: # iterate over the deque's elements ...
🌐
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.
🌐
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.
🌐
Dataquest
dataquest.io › blog › python-deque-queues-stacks
Python Deque Function: A Better Choice for Queues and Stacks – Dataquest
April 7, 2025 - Learn how the deque() function from the collections module can be a much better choice when you need to implement queues and stacks in Python
🌐
Tutorialspoint
tutorialspoint.com › python › python_collections_deque.htm
Python collections.deque
Following is an basic example of Python deque() class − · from collections import deque d = deque('xyz') print(d)
🌐
Python Engineer
python-engineer.com › posts › deque-python
Deque in Python using Collections Module - Python Engineer
June 1, 2022 - In this tutorial, we have learned the basics of Deque in Python using the collections module. We have also learned how to use the built-in functions available in the collections module to perform the operations on the deque.
Find elsewhere
🌐
Real Python
realpython.com › python-deque
Python's deque: Implement Efficient Queues and Stacks – Real Python
January 12, 2026 - Python’s deque returns mutable sequences that work quite similarly to lists. Besides allowing you to append and pop items from their ends efficiently, deques provide a group of list-like methods and other sequence-like operations to work with ...
🌐
Zenva
gamedevacademy.org › home › python › python deque in collections tutorial – complete guide
Python Deque In Collections Tutorial - Complete Guide - GameDev Academy
December 12, 2023 - Let’s begin our journey in understanding DeQue with a simple example. Firstly, to use deque in Python, you need to import it from the collections module:
🌐
Real Python
realpython.com › lessons › collectionsdeque
collections.deque (Video) – Real Python
... In this lesson, you’ll use the collections.deque data structure to create a ticketing queue. Deques allow for appending to both left and right and popping from both left and right in constant time.
Published   April 21, 2020
🌐
Tutorialspoint
tutorialspoint.com › python › python_deque.htm
Python - Deque
In the below program we import the collections module and declare a deque. Without need of any class we use the in-built implement these methods directly. import collections # Create a deque DoubleEnded = collections.deque(["Mon","Tue","Wed"]) print (DoubleEnded) # Append to the right print("Adding to the right: ") DoubleEnded.append("Thu") print (DoubleEnded) # append to the left print("Adding to the left: ") DoubleEnded.appendleft("Sun") print (DoubleEnded) # Remove from the right print("Removing from the right: ") DoubleEnded.pop() print (DoubleEnded) # Remove from the left print("Removing from the left: ") DoubleEnded.popleft() print (DoubleEnded) # Reverse the dequeue print("Reversing the deque: ") DoubleEnded.reverse() print (DoubleEnded)
🌐
Python Module of the Week
pymotw.com › 2 › collections › deque.html
Deque - Python Module of the Week
Now available for Python 3! Buy the book! ... A double-ended queue, or deque, supports adding and removing elements from either end. The more commonly used stacks and queues are degenerate forms of deques, where the inputs and outputs are restricted to a single end. import collections d = ...
🌐
Allendowney
allendowney.github.io › DSIRP › deque.html
Deque — Data Structures and Information Retrieval in Python
deque = Deque() left_push(deque, 2) left_push(deque, 1) print(deque) ... The Python collections module provides an implementation of a deque.
🌐
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 - Deque in Python 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 …
🌐
datagy
datagy.io › home › python collections › python collections deque – stacks and queues
Python Collections deque - Stacks and Queues • datagy
December 16, 2022 - In this tutorial, you’ll learn how to use the Python collection’s module deque class.
🌐
HackerRank
hackerrank.com › challenges › py-collections-deque › problem
Collections.deque() | HackerRank
Click on the link to learn more about various approaches to working with deques: Deque Recipes. ... >>> from collections import deque >>> d = deque() >>> d.append(1) >>> print d deque([1]) >>> d.appendleft(2) >>> print d deque([2, 1]) >>> d.clear() >>> print d deque([]) >>> d.extend('1') >>> print d deque(['1']) >>> d.extendleft('234') >>> print d deque(['4', '3', '2', '1']) >>> d.count('1') 1 >>> d.pop() '1' >>> print d deque(['4', '3', '2']) >>> d.popleft() '4' >>> print d deque(['3', '2']) >>> d.extend('7896') >>> print d deque(['3', '2', '7', '8', '9', '6']) >>> d.remove('2') >>> print d deque(['3', '7', '8', '9', '6']) >>> d.reverse() >>> print d deque(['6', '9', '8', '7', '3']) >>> d.rotate(3) >>> print d deque(['8', '7', '3', '6', '9'])
🌐
Netalith
netalith.com › blogs › computer-science › python-collections-module-tutorial-2026
Python Collections Module Tutorial: Guide to High-Performance Data Structures
1 month ago - An advanced Python collections module tutorial covering specialized data structures like namedtuple, deque, and Counter for optimized performance.
🌐
FavTutor
favtutor.com › blogs › deque-python
Python Deque: Example, Implementation & Methods (with code)
March 15, 2023 - A deque is defined in the code below by giving the list's name (list_name) to the deque() module, which was loaded from the collections library. Furthermore, we can see that no special class is required to make use of these in-built methods.