From the course: Advanced Python: Working With Data
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
The deque class - Python Tutorial
From the course: Advanced Python: Working With Data
The deque class
- [Instructor] The last collection class that we will take a look at in this chapter is called a deque. Now, the name may look like it says dq, but it's actually pronounced deck, and it's a sort of a hybrid object between a stack and a queue. In fact, the name itself basically stands for double-ended queue. That's where the de comes from. And you can use them to append or pop data from either side. And they're designed to be memory efficient when accessing data from either end. Deques can be initialized to either be empty or get their initial data from any existing iterable object. In this case, I'm using a string. They can also be specified to have a maximum length. To add data to a deque, you use the append method to add items on the end or the right side and appendleft to add items to the beginning. And similarly, items can be removed using either pop or popleft. Deques also support a rotate function which can…