VOOZH about

URL: https://www.geeksforgeeks.org/python/python-queue-lifoqueue-vs-collections-deque/

⇱ Python - Queue.LIFOQueue vs Collections.Deque - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python - Queue.LIFOQueue vs Collections.Deque

Last Updated : 23 Jul, 2025

Both LIFOQueue and Deque can be used using in-built modules Queue and Collections in Python, both of them are data structures and are widely used, but for different purposes. In this article, we will consider the difference between both Queue.LIFOQueue and Collections.Deque concerning usability, execution time, working, implementation, etc. in Python.

queue.LifoQueue: The module queue provides a LIFO Queue which technically works as a Stack. It is usually used for communication between the different threads in the very same process.

Below is a program which depicts the implementation of Lifo.Queue:

Output:

0
Full: True
Size: 3
3
2
1
Empty: True

collections.deque: Deque (Doubly Ended Queue) in Python is implemented using the module collections. This data structure is mainly used for queues. The FIFO queue mechanism is implemented by append() and popleft(). It's operations are quite faster as compared to lists.

Below is a program that illustrates the implementation of collections.deque:

Output:

The deque after appending at right is: deque([10, 20, 30, 0])
The deque after appending at left is: deque([100, 10, 20, 30, 0])
The deque after deleting from right is: deque([100, 10, 20, 30])
Queue: deque([10, 20, 30])

Difference between LIFOQueue and Deque:

Sr. no.LIFO QueueDequeue
1It implements stacksIt implements a double-edged queue
2Present in Queue modulePresent in Collections module
3Allows various threads to communicate using queued data or messagesSimply intended to be a data structure
4Fewer features (operations and methods)Large Variety of features (operations and methods)
5Follows Last In First OutFollows both FIFO and LIFO
6Slow operations (long execution time)High operations(very low execution time)
6Not commonly used, usually used for thread communication operations.Mostly used for data structure operations.
Comment
Article Tags: