🌐
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 ...
Discussions

Hello, Guys. I am trying to understand the queue and deque in Python.

Why are you using version 2.5? That’s pretty out of date.

More on reddit.com
🌐 r/learnprogramming
2
1
June 15, 2022
Can someone help me understand what collections.deque() in this example code does?

You're familiar with lists? It functions very similarly to a list. Like you can read from the documentaion, there's some optimization reason why the data structure is selected to be a deque instead of list, but from usage perspective they're quite identical.

An empty list vs. deque would be:

a_list = []
a_deque = collections.deque()

Initialized to some starting values instead of being empty:

a_list = [1,2,3]
a_deque = collections.deque([1,2,3])

And a way to initialize same value several times is to say [a_value]*n for example [1]*3 would be same as [1,1,1]. So finally the differences for that type of initialization:

a_list = [0.0]*buffer_size
a_deque = collections.deque([0.0]*buffer_size)

And then the only last difference to the actual code is that they also set a maximum length of the deque object so it can't ever hold more values than that.

More on reddit.com
🌐 r/learnpython
2
1
May 6, 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
People also ask

Is the collection module a necessary topic for Python?
Yes, the collection module is a necessary topic while learning Python. Counting objects, constructing queues and stacks, managing missing keys in dictionaries, and more are all possible with Python's collections module. Collections' data types and classes are created to be efficient and Pythonic. They are pretty valuable for your Python programming career, so taking the time to learn about this collection module is well worth your time and effort. The containers in the Collections module may be quite beneficial for business-level projects and models, adding significantly to the usefulness of g
🌐
upgrad.com
upgrad.com › home › blog › data science › python collections module: counter, chainmap, deque & tuple
Python Collections Module: Counter, ChainMap, Deque & Tuple | upGrad ...
What are the data types present in the collection Module?
Several data types are present in the collection module, such as deque, defaultdict, namedtuple, OrderedDict, Counter, ChainMap, UserDict, UserList, UserString, etc. These data types can be used for various reasons, such as adding and removing items from either end of the sequence, constructing default values for missing keys, and automatically adding them to the dictionary. These data types can also help by providing named fields that allow accessing items by name while keeping the ability to access items by index, counting unique items in a sequence or iterable, and treating several mappings
🌐
upgrad.com
upgrad.com › home › blog › data science › python collections module: counter, chainmap, deque & tuple
Python Collections Module: Counter, ChainMap, Deque & Tuple | upGrad ...
What is a collection module, and how is it useful?
Python's collection module supports several types of containers. A Container is an object used to store various items and give the means to retrieve and iterate over the enclosed objects. Tuple, List, Dictionary, and more built-in containers are available. Also, the Collections module has highly specialized and efficient container data types such as namedtuple(), deque, OrderedDict, counter, and so on that are far superior to standard Python containers.
🌐
upgrad.com
upgrad.com › home › blog › data science › python collections module: counter, chainmap, deque & tuple
Python Collections Module: Counter, ChainMap, Deque & Tuple | upGrad ...
🌐
ActiveState
code.activestate.com › recipes › 259179-deque-collection-class
deque collection class « Python recipes « ActiveState Code
January 12, 2004 - See documentation at: http://www.python.org/dev/doc/devel/lib/module-collections.html <br> Uses a dictionary as the underlying data structure for the deque (pronounced "deck", short for "double-ended queue", a generalization of stacks and queues) which provides O(1) performance for appends and pops from either end.
🌐
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.
🌐
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. This makes it useful in applications like task scheduling, sliding window problems and real-time ...
Published   5 days ago
🌐
GeeksforGeeks
geeksforgeeks.org › python › implementation-of-deque-using-list-in-python
Implementation of Deque Using List in Python - GeeksforGeeks
July 23, 2025 - A Deque (double-ended queue) is a data structure that allows insertion and deletion from both the front and rear. Deques are widely used in applications requiring efficient access and modification at both ends.
Find elsewhere
🌐
PyPI
pypi.org › project › pycopy-collections.deque
pycopy-collections.deque · PyPI
collections.deque module for Pycopy
      » pip install pycopy-collections.deque
    
Published   Jul 14, 2019
Version   0.1.3
🌐
Upgrad
upgrad.com › home › blog › data science › python collections module: counter, chainmap, deque & tuple
Python Collections Module: Counter, ChainMap, Deque & Tuple | upGrad blog
November 24, 2025 - The containers in the Collections module may be quite beneficial for business-level projects and models, adding significantly to the usefulness of generic Python containers through improved optimization and execution speed. Several data types are present in the collection module, such as deque, defaultdict, namedtuple, OrderedDict, Counter, ChainMap, UserDict, UserList, UserString, etc.
🌐
Programiz
programiz.com › java-programming
Learn Java Programming
Java Collection Interface · Java List · Java ArrayList · Java Vector · Java Stack Class · Java Queue · Java Queue Interface · Java PriorityQueue · Java Deque Interface · Java LinkedList · Java ArrayDeque · Java BlockingQueue · Java ArrayBlockingQueue ·
🌐
Udemy
udemy.com › development
The Ultimate Python Bootcamp: Learn by Building 50 Projects
March 6, 2026 - Other collections types like deque, ChainMap, and Counter are briefly noted. The video emphasizes that these advanced types, accessed via import statements, extend Python's core functionalities for specialized tasks, encouraging learners to revisit them as their programming journey progresses ...
Rating: 4.5 ​ - ​ 2.22K votes
🌐
SDSU
edoras.sdsu.edu › doc › Python-Docs-2.5 › lib › deque-objects.html
5.3.1 deque objects
September 19, 2006 - Previous: 5.3 collections Up: 5.3 collections Next: 5.3.1.1 Recipes · Returns a new deque objected initialized left-to-right (using append()) with data from iterable.
🌐
Dummies
dummies.com › article › technology › programming-web-design › python › working-deques-python-250567
Working with Deques in Python | dummies
June 28, 2025 - Unlike some other collections, a deque is fully iterable. This means that you can obtain a list of items by using a for loop whenever necessary. Click Run Cell. Python outputs the information (the screenshot shows only the output and none of the code).
🌐
FavTutor
favtutor.com › blogs › deque-python
Python Deque: Example, Implementation & Methods (with code)
March 15, 2023 - A class called deque can be found in Python's collections module which is optimized for quick operations like appending and popping items from either end of the underlying data structure.
🌐
SSOJet
ssojet.com › data-structures › implement-deque-in-python
Implement Deque in Python | Implement Data Structures in Programming Languages
You can create a deque in Python either empty or pre-populated with elements from an existing iterable, such as a list or tuple. To initialize, simply pass the iterable to the deque constructor. from collections import deque # Initialize with a list my_list = [10, 20, 30] d1 = deque(my_list) print(d1) # Output: deque([10, 20, 30]) # Initialize an empty deque d2 = deque() print(d2) # Output: deque([])
🌐
PyPI
pypi.org › project › pydantic
pydantic · PyPI
Move deque schema gen to GenerateSchema class by @sydney-runkle in #11239 · Move Mapping schema gen to GenerateSchema to complete removal of prepare_annotations_for_known_type workaround by @sydney-runkle in #11247 · Remove Python 3.8 Support by @sydney-runkle in #11258
      » pip install pydantic
    
Published   Apr 20, 2026
Version   2.13.3
🌐
Towards Data Science
towardsdatascience.com › home › latest › python collections module: the forgotten data containers
Python Collections Module: The Forgotten Data Containers | Towards Data Science
March 5, 2025 - The deque should be your go-to data structure when you want a queue and do not care about multithreading. While deques are threadsafe, queues from the Queue module are better suited.
🌐
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.
🌐
CodeConverter
codeconverter.com › articles › deque-python
Deque Python — Guide with Examples | CodeConverter Blog
February 11, 2026 - A deque (short for double-ended queue) is a data structure that allows you to efficiently add and remove elements from both ends. It's part of Python's built-in `collections` module and is implemented as a doubly linked list.
🌐
Medium
medium.com › @sanjula99perera › efficient-queue-implementation-in-python-using-collections-deque-2446908ffa34
“Efficient Queue Implementation in Python Using collections.deque” | by Sanjulaperera | Medium
May 28, 2024 - The deque class from the collections module provides an efficient way to implement a queue. It offers O(1) time complexity for both append and pop operations.