Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Using Sequence-Like Features of Deque
00:00
Since deques are mutable sequences, they implement almost all the methods and operations that are common to sequences and mutable sequences.
00:09
So far in the course, you’ve learned about some of these methods and operations, such as .insert(), indexing, membership tests, and others. Now, you’ll see a few other examples.
00:20
You can use the plus operator to return a new deque that’s a concatenation of two existing deques. The multiplication operator returns a new deque equivalent to repeating the original deque as many times as you specify.
00:34
So, let’s review the sequence that we originally had, and you can use .index() to get the position of a value in the deque.
00:46
.count() returns the number of times a value appears in the target deque,
00:52
and you can also reverse the elements of the deque in place.
00:58
You can use .clear() to remove all elements from a deque, so now it’s an empty deque. In the next lesson, you’ll explore a practical use case for deque by using it to keep track of a page history.
Become a Member to join the conversation.