Some answers claimed a "10x" speed advantage for deque vs list-used-as-FIFO when both have 1000 entries, but that's a bit of an overbid:

$ python -mtimeit -s'q=range(1000)' 'q.append(23); q.pop(0)'
1000000 loops, best of 3: 1.24 usec per loop
$ python -mtimeit -s'import collections; q=collections.deque(range(1000))' 'q.append(23); q.popleft()'
1000000 loops, best of 3: 0.573 usec per loop

python -mtimeit is your friend -- a really useful and simple micro-benchmarking approach! With it you can of course also trivially explore performance in much-smaller cases:

$ python -mtimeit -s'q=range(100)' 'q.append(23); q.pop(0)'
1000000 loops, best of 3: 0.972 usec per loop
$ python -mtimeit -s'import collections; q=collections.deque(range(100))' 'q.append(23); q.popleft()'
1000000 loops, best of 3: 0.576 usec per loop

(not very different for 12 instead of 100 items btw), and in much-larger ones:

$ python -mtimeit -s'q=range(10000)' 'q.append(23); q.pop(0)'
100000 loops, best of 3: 5.81 usec per loop
$ python -mtimeit -s'import collections; q=collections.deque(range(10000))' 'q.append(23); q.popleft()'
1000000 loops, best of 3: 0.574 usec per loop

You can see that the claim of O(1) performance for deque is well founded, while a list is over twice as slow around 1,000 items, an order of magnitude around 10,000. You can also see that even in such cases you're only wasting 5 microseconds or so per append/pop pair and decide how significant that wastage is (though if that's all you're doing with that container, deque has no downside, so you might as well switch even if 5 usec more or less won't make an important difference).

Answer from Alex Martelli on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ queue-in-python
Queue in Python - GeeksforGeeks
May 29, 2026 - There are various ways to implement a queue in Python by following ways: Lists can be used as queues, but removing elements from front requires shifting all other elements, making it O(n).
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dsa_queues.asp
Queues with Python
Queues can be implemented by using arrays or linked lists. Queues can be used to implement job scheduling for an office printer, order processing for e-tickets, or to create algorithms for breadth-first search in graphs.
Discussions

Normal Queue vs Lists?
As I understand, both list.pop(0) and dequeue.popleft() operate in O(1). This is incorrect, because as you note: when you pop(0) a list, it needs to move all the memory "to the side 1 space" so to speak. This means list.pop(0) operates in O(n). collections.deque will be far more efficient as a FIFO queue, though list is an efficient stack. More on reddit.com
๐ŸŒ r/learnpython
4
5
May 6, 2016
Implementing an efficient queue in Python - Stack Overflow
I have been trying to implement a queue in Python, and I've been running into a problem. I am attempting to use lists to implement the queue data structure. However I can't quite figure out how to ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is it possible to convert list to queue in python? - Stack Overflow
How to convert a list to queue? So that operations like enqueue or dequeue an be carried out. I want to use to the list to remove the top most values and i believe it can be done using queues. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Initialize queue from an existing list - Ideas - Discussions on Python.org
I am writing a code that uses queues and lists, and every time I need to create a queue from a list, what I do is l = [1, 2, 3, 4, 5] # existing list q = queue.Queue() for e in l: q.put(e) This actually works, but this is O(n). How about enhancing queue.XXXQueue classes to accept a list on ... More on discuss.python.org
๐ŸŒ discuss.python.org
0
July 5, 2022
Top answer
1 of 5
88

Some answers claimed a "10x" speed advantage for deque vs list-used-as-FIFO when both have 1000 entries, but that's a bit of an overbid:

$ python -mtimeit -s'q=range(1000)' 'q.append(23); q.pop(0)'
1000000 loops, best of 3: 1.24 usec per loop
$ python -mtimeit -s'import collections; q=collections.deque(range(1000))' 'q.append(23); q.popleft()'
1000000 loops, best of 3: 0.573 usec per loop

python -mtimeit is your friend -- a really useful and simple micro-benchmarking approach! With it you can of course also trivially explore performance in much-smaller cases:

$ python -mtimeit -s'q=range(100)' 'q.append(23); q.pop(0)'
1000000 loops, best of 3: 0.972 usec per loop
$ python -mtimeit -s'import collections; q=collections.deque(range(100))' 'q.append(23); q.popleft()'
1000000 loops, best of 3: 0.576 usec per loop

(not very different for 12 instead of 100 items btw), and in much-larger ones:

$ python -mtimeit -s'q=range(10000)' 'q.append(23); q.pop(0)'
100000 loops, best of 3: 5.81 usec per loop
$ python -mtimeit -s'import collections; q=collections.deque(range(10000))' 'q.append(23); q.popleft()'
1000000 loops, best of 3: 0.574 usec per loop

You can see that the claim of O(1) performance for deque is well founded, while a list is over twice as slow around 1,000 items, an order of magnitude around 10,000. You can also see that even in such cases you're only wasting 5 microseconds or so per append/pop pair and decide how significant that wastage is (though if that's all you're doing with that container, deque has no downside, so you might as well switch even if 5 usec more or less won't make an important difference).

2 of 5
47

You won't run out of memory using the list implementation, but performance will be poor. From the 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.

So using a deque will be much faster.

๐ŸŒ
Medium
medium.com โ€บ @avgengineerx01 โ€บ queue-in-python-using-a-list-6f7d7f7af3cd
Queue in Python using a List. We can implement a queue in Pythonโ€ฆ | by AvgEngineer | Medium
September 10, 2023 - #Declaring our queues in the form of a list q = [] #Inserting the elements into our queue using the append function q.append(1) #[1] q.append(2) #[1, 2] q.append(3) #[1, 2, 3] q.append(4) #[1, 2, 3, 4] #elements got inserted from the back side print(q) #Result:- [1, 2, 3, 4] #Now when we want to take out an element from queue it should from front q.pop(0) # here 0 means 0th index # 1 will be popped out as it was at 0th index and the first element print(q) #[2, 3, 4] #next front element is 2 so it will get popped out q.pop(0) print(q) #[3, 4]
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ implementation-of-queue-using-list-in-python
Implementation of Queue using List in Python - GeeksforGeeks
July 23, 2025 - A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first. In Python, we can implement a queue using both a regular list and a circular list.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-implement-a-queue-in-python
How to implement a queue in Python
Python implements queues using lists, collections.deque for efficient operations, and the queue module for thread-safe FIFO queues.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ queue.html
queue โ€” A synchronized queue class
The module implements three types of queue, which differ only in the order in which the entries are retrieved. In a FIFO queue, the first tasks added are the first retrieved. In a LIFO queue, the most recently added entry is the first retrieved ...
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ normal queue vs lists?
r/learnpython on Reddit: Normal Queue vs Lists?
May 6, 2016 -

Reading the code on a Queue

queue.Queue

This just seems like a fancy list initialized as a dequeue which only .get()s the first item of a list.

As I understand, both list.pop(0) and dequeue.popleft() operate in O(1).

The only difference that I notice is that when you pop(0) a list, it needs to move all the memory "to the side 1 space" so to speak. Is this the only real difference between dequeues and lists?

Should I just use a list as a FIFO, or is a list better for LIFO\Stack?

๐ŸŒ
Quora
quora.com โ€บ How-do-you-convert-a-list-to-a-queue-in-Python
How to convert a list to a queue in Python - Quora
Answer (1 of 2): Queue is a linear data structure which follows FIFO (First In First Out) principle. Yes, you can convert a list to queue in Python using the following code. [code]import queue lst = [1,2,3,4] q = queue.Queue() [q.put(i) for i in lst] print(lst) print(type(lst)) print(q) print(t...
Top answer
1 of 8
41

As Uri Goren astutely noted above, the Python stdlib already implemented an efficient queue on your fortunate behalf: collections.deque.

What Not to Do

Avoid reinventing the wheel by hand-rolling your own:

  • Linked list implementation. While doing so reduces the worst-case time complexity of your dequeue() and enqueue() methods to O(1), the collections.deque type already does so. It's also thread-safe and presumably more space and time efficient, given its C-based heritage.
  • Python list implementation. As I note below, implementing the enqueue() methods in terms of a Python list increases its worst-case time complexity to O(n). Since removing the last item from a C-based array and hence Python list is a constant-time operation, implementing the dequeue() method in terms of a Python list retains the same worst-case time complexity of O(1). But who cares? enqueue() remains pitifully slow.

To quote the official deque documentation:

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.

More critically, deque also provides out-of-the-box support for a maximum length via the maxlen parameter passed at initialization time, obviating the need for manual attempts to limit the queue size (which inevitably breaks thread safety due to race conditions implicit in if conditionals).

What to Do

Instead, implement your Queue class in terms of the standard collections.deque type as follows:

from collections import deque

class Queue:
    '''
    Thread-safe, memory-efficient, maximally-sized queue supporting queueing and
    dequeueing in worst-case O(1) time.
    '''


    def __init__(self, max_size = 10):
        '''
        Initialize this queue to the empty queue.

        Parameters
        ----------
        max_size : int
            Maximum number of items contained in this queue. Defaults to 10.
        '''

        self._queue = deque(maxlen=max_size)


    def enqueue(self, item):
        '''
        Queues the passed item (i.e., pushes this item onto the tail of this
        queue).

        If this queue is already full, the item at the head of this queue
        is silently removed from this queue *before* the passed item is
        queued.
        '''

        self._queue.append(item)


    def dequeue(self):
        '''
        Dequeues (i.e., removes) the item at the head of this queue *and*
        returns this item.

        Raises
        ----------
        IndexError
            If this queue is empty.
        '''

        return self._queue.pop()

The proof is in the hellish pudding:

>>> queue = Queue()
>>> queue.enqueue('Maiden in Black')
>>> queue.enqueue('Maneater')
>>> queue.enqueue('Maiden Astraea')
>>> queue.enqueue('Flamelurker')
>>> print(queue.dequeue())
Flamelurker
>>> print(queue.dequeue())
Maiden Astraea
>>> print(queue.dequeue())
Maneater
>>> print(queue.dequeue())
Maiden in Black

It Is Dangerous to Go Alone

Actually, don't do that either.

You're better off just using a raw deque object rather than attempting to manually encapsulate that object in a Queue wrapper. The Queue class defined above is given only as a trivial demonstration of the general-purpose utility of the deque API.

The deque class provides significantly more features, including:

...iteration, pickling, len(d), reversed(d), copy.copy(d), copy.deepcopy(d), membership testing with the in operator, and subscript references such as d[-1].

Just use deque anywhere a single- or double-ended queue is required. That is all.

2 of 8
10

You can keep head and tail node instead of a queue list in queue class

class Node:
    def __init__(self, item = None):
        self.item = item
        self.next = None
        self.previous = None


class Queue:
    def __init__(self):
        self.length = 0
        self.head = None
        self.tail = None

    def enqueue(self, value):
        newNode = Node(value)
        if self.head is None:
            self.head = self.tail = newNode
        else:
            self.tail.next = newNode
            newNode.previous = self.tail
            self.tail = newNode
        self.length += 1

    def dequeue(self):
        item = self.head.item
        self.head = self.head.next 
        self.length -= 1
        if self.length == 0:
            self.tail = None
        return item
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.6 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']) List comprehensions provide a concise way to create lists.
๐ŸŒ
Real Python
realpython.com โ€บ lessons โ€บ queues-with-list-and-deque
Queues With list and deque (Video) โ€“ Real Python
00:29 Like stacks, queues donโ€™t ... search of a tree-like data structure. 00:51 The built-in list type in Python can be used as a queue by popping items off the front of the list....
Published ย  May 11, 2021
๐ŸŒ
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 ...
Python lists, however, have a significant drawback: the pop(0) method has ... O(1)O(1). There is another Python module named collections that offers deque, a flexible container that serves both as queue and stack implementations.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python_data_structure โ€บ python_queue.htm
Python Data Structure - Queue
A queue can be implemented using python list where we can use the insert() and pop() methods to add and remove elements.
๐ŸŒ
Python.org
discuss.python.org โ€บ ideas
Initialize queue from an existing list - Ideas - Discussions on Python.org
July 5, 2022 - I am writing a code that uses queues and lists, and every time I need to create a queue from a list, what I do is l = [1, 2, 3, 4, 5] # existing list q = queue.Queue() for e in l: q.put(e) This actually works, but this is O(n). How about enhancing queue.XXXQueue classes to accept a list on ...
๐ŸŒ
Boot.dev
boot.dev โ€บ blog โ€บ python โ€บ queue data structure in python: ordering at its best
Queue Data Structure in Python: Ordering at Its Best | Boot.dev
June 18, 2026 - If we use a linked list instead of a normal list, we can avoid this problem completely. With a linked list, we can enqueue and dequeue in O(1) time. Here's a simple linked list-based queue:
๐ŸŒ
Javatpoint
javatpoint.com โ€บ queue-in-python
Queue in Python - Javatpoint
Queue in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, basics, data types, operators, etc.