Implementing Deque in Python
Lesson 1 of 1
  1. 1
    A deque, which stands for double-ended queue, is a data structure that allows users to insert and delete items at both ends of the queue. Because we can insert and delete from both ends, a deque …
  2. 2
    Imagine we want to board (or insert) a passenger from the front door of the plane. To insert items into the front of the deque, we need to implement an add_first(item) method. This method should: …
  3. 3
    Imagine we want to board (or insert) a passenger from the rear door of the plane. To insert items into the rear of the deque, we need to implement an add_last(item) method. This method should: * …
  4. 4
    The flight has landed, and it’s time to deboard the passengers. When we remove a passenger from the front door of the plane, we must remove them from the front of the deque. To remove an item from …
  5. 5
    We can deboard the rear passengers while we deboard the front passengers thanks to the flexibility of the deque structure. When we remove a passenger from the rear door of the plane, we must remove…
  6. 6
    You may need a way to determine if the plane is empty of passengers (to ensure everyone has deboarded) or to see exactly how many passengers are on board. To do this, we can implement two methods: …
  7. 7
    Congratulations! You’ve completed the lesson and have learned what deques are and how to implement one in Python. We have covered: * What a deque is and how it relates to queues and stacks * What …

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo