deque - double ended queue
https://docs.python.org/2/library/collections.html
class collections.deque([iterable[, maxlen]])
Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”). Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.
create a new deque object:
deque([1])
or
start = deque()
start.append(1)
plenty of methods:
append(x), appendleft(x), pop(), popleft(), remove(value), extend(iterable), extendleft(iterable)
defaultdict
Returns a new dictionary-like object.defaultdict
is a subclass of the built-indict
class.
>>> s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
>>> d = defaultdict(list)
>>> for k, v in s:
... d[k].append(v)
...
>>> d.items()
[('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])]
Counter
A counter is a dict subclass for counting hashtable objects.
>>> c = Counter()
>>> c['cnt'] += 1
>>> c
Counter({'cnt': 1})
>>>