The collections module also contains support for the deque object. The deque object is typically used to perform fast operations on the beginning and and of a list. It should only be used when you care more about manipulating data and taking items from the beginning and end of the list rather than random lookups of elements.
To create a new deque we can do the following:
The deque object allows for appending to the beginning and end of the deque. It also allows us to pop elements from either end.
The deque object also has some other useful methods.
.clear(): This will empty the deque object.
.extend(iterable): This will add all of the items from the passed iterbale data type or collection to the end of the deque. .extendleft() words the same way
.rotate(n): Given an int n this method will rotate the deck that many positions. The given int can be negative or positive. If it is negative it will rotate the deque to the left, otherwise it will rotate to the right.
If you benefited from these tutorials and appreciate the hard work I put into creating my videos and writing these guides please consider supporting me and the content. Any amount helps and your donations and support is what keeps techwithim.net up and running.