collections

The collections module contains high-performance implementations of various container data types. This is a relatively new Python module that only contains a single object as of this writing. However, it may be expanded in future releases.

deque([iterable])

Creates a double-ended queue (deque) object. iterable is an iterable object used to populate the deque. A deque allows items to be inserted or removed from either end of the queue. The implementation has been optimized so that the performance of these operations is approximately the same (O(1)). This is slightly different from a list where operations at the front of the list may require shifting of all the elements that follow.

An instance, d, of deque has the following methods: ...

Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.