The collections Module
The collections module (introduced in Python 2.4) is intended to eventually supply several interesting types that are collections (i.e., containers).
deque
In Python 2.4, the collections module supplies only one type, deque, whose instances are “double-ended queues” (i.e., sequence-like containers suitable for additions and removals at both ends). Call deque with a single argument, any iterable, to obtain a new deque instance whose items are those of the iterable in the same order, or call deque without arguments to obtain a new empty deque instance. A deque instance d is a mutable sequence and thus can be indexed and iterated on (however, d cannot be sliced, only indexed one item at a time, whether for access, rebinding, or deletion). A deque instance d supplies the following methods.
append |
Appends |
appendleft |
Appends |
clear |
Removes all items from |
extend |
Appends all items of |
extendleft |
Appends all items of |
pop |
Removes and returns the last (rightmost) item from |
popleft |
Removes and returns the first (leftmost) item from |
rotate |
Rotates |
defaultdict
In Python 2.5, the collections module also supplies type defaultdict ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access