Working With Python's deque

Roxana Anabel Lafuente 13 Lessons 57m Updated intermediate data-structures python stdlib

You can use Python’s deque for efficient appends and pops at both ends of a sequence-like data type. These capabilities are critical when you need to implement queue and stack data structures that operate efficiently even under heavy workloads.

In this video course, you’ll learn how deque works, when to use it over a list, and how to apply it in real code.

By the end of this course, you’ll understand that:

  • deque internally uses a doubly linked list, so end operations are O(1) while random indexing is O(n).
  • You can build a FIFO queue with .append() and .popleft(), and a LIFO stack with .append() and .pop().
  • deque supports indexing but doesn’t support slicing.
  • Passing a value to maxlen creates a bounded deque that drops items from the opposite end when full.
  • In CPython, .append(), .appendleft(), .pop(), .popleft(), and len() are thread-safe for multithreaded use.

Up next, you’ll get started with deque, benchmark it against list, and explore how it shines in real-world use cases, such as queues, stacks, history buffers, and thread-safe producer-consumer setups.

What’s Included:

  • 13 Lessons
  • Video Subtitles and Full Transcripts
  • 2 Downloadable Resources
  • Accompanying Text-Based Tutorial
  • Interactive Quiz to Check Your Progress
  • 3 Hands-On Coding Exercises
  • Q&A With Python Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

About Roxana Anabel Lafuente

Roxana is a software engineer and coding educator with 8+ years of experience. She studied computer science at the Universidad Nacional de Córdoba and has worked with companies including Booking.com and Yelp, as well as Electronic Arts and Intel.

» More about Roxana Anabel

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

← Browse All Courses