From the course: Advanced Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Deque objects

Deque objects - Python Tutorial

From the course: Advanced Python

Start my 1-month free trial

Deque objects

- [Instructor] The last collection class that we'll take a look at in this chapter is called a deque. Now the name may look like it says de queue, but it's actually pronounced deque, and it's sort of a hybrid object between a stack and a queue. In fact, the name itself basically means double-ended queue. You can use them to append or pop data from either side, and they are designed to be memory-efficient when accessing them from either end. Deques can be initialized to be either empty or get their initial data from an existing, iterable object, and they can also be specified to have a maximum length. To add data to a deque, you use either the append or append left methods to add items onto the end or the beginning, and similarly, items can be removed using either pop or pop left. Deques also support a rotate function, which can operate in either direction. The rotate function takes a parameter indicating how many items to rotate and defaults to one, so positive numbers will rotate to…

Contents