The remove_rear() and remove_front() methods remove and return items from either end of the deque. In this video, learn how to use the Python list's built-in pop() method to implement this behavior.
- [Narrator] If we want to remove something from the…front of our deck, which is represented by…the left side of our list,…we can use the list's built-in pop method,…and simply pass the index that we want to remove…into that pop method.…That would look something like this.…Return self dot items dot pop,…and will pass in the zeroth index to that pop method.…The remove rear method is almost identical.…The only difference is that we don't have to…pass in that zeroth index because the built-in…pop method, by default, will always return…and remove the last item of a list.…
Let's save this and we'll go back to the terminal…and test this out.…First thing I'll do is create my own deck object.…And let's add a couple items here.…We'll do add front apple,…and banana,…and how about one more, we'll add carrot,…and just for fun we can check our items attribute…and that's exactly what we get,…we can see that every time we've been adding…a new string to the front of the list.…
Let's try out our new remove front method.…If we do my d dot remove front,…
- Abstract types and data structures
- Stacks as a linear abstract data type
- Creating the Stack class and its methods
- Adding items to the top and bottom of a stack
- Creating the Queue class and its methods
- Manipulating items in a queue
- Creating the Dequeue class and its methods
- Adding and removing items from a dequeue
Skill Level Advanced
Learning the Python 3 Standard Librarywith Kathryn Hodge2h 9m Intermediate
What you should know1m 26s
1. Abstract Data Types and Data Structures
2. The Stack
3. The Queue
4. The Deque
Next steps1m 43s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.