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 them from the rear of the deque. To remove an item from the rear of the deque, we need to use a remove_last() method to do so. The removed item will be returned by this method, allowing us to use the popped item elsewhere in the code.

The remove_last() method should:

  • Pop the last (or leftmost at index 0) item from the elements list.
  • Return the popped item at the end of the method.

The time complexity of this method is O(1), constant time, since only one iteration of executing the method is needed to remove and return the last item from the elements list.



Implement the remove_last() method based on the above implementation details in Python.


Test calling the remove_last() method and set the returned value to a variable called popped_rear.


Print the value of popped_rear to verify that the item popped from the deque is value 42.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?