Learn

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: is_empty() and size(). These methods are also helpful in making sure we avoid calling our deque methods on an empty deque.

To determine if the deque is empty, we implement the is_empty() method, which should:

  • Return True if the deque is empty (has 0 items in the elements list) or False if the deque contains one or more elements.

To obtain the size of the deque, we implement the size() method, which should:

  • Return the length of the deque(the number of items in the elements list).

Instructions

1.

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

2.

Test calling the is_empty() method and print out the returned value.

3.

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

4.

Test calling the size() method and print out the returned value.

5.

Call the remove_first() method and call both the is_empty() and size() methods again, printing out both returned values.

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?