(For more about ABCs, see the :mod:`abc` module and :pep:`3119`.)
-.. _counter-objects:
-
:class:`Counter` objects
------------------------
Counter({'a': 4, 'b': 3})
>>> c - d # subtract (keeping only positive counts)
Counter({'a': 2})
- >>> c & d # interection: min(c[x], d[x])
+ >>> c & d # intersection: min(c[x], d[x])
Counter({'a': 1, 'b': 1})
>>> c | d # union: max(c[x], d[x])
Counter({'a': 3, 'b': 2})
Section 4.6.3, Exercise 19
-
-.. _deque-objects:
-
:class:`deque` objects
----------------------
-
.. class:: deque([iterable[, maxlen]])
Returns a new deque object initialized left-to-right (using :meth:`append`) with
deque(['c', 'b', 'a'])
-.. _deque-recipes:
-
:class:`deque` Recipes
^^^^^^^^^^^^^^^^^^^^^^
'Return the last n lines of a file'
return deque(open(filename), n)
-.. _defaultdict-objects:
:class:`defaultdict` objects
----------------------------
-
.. class:: defaultdict([default_factory[, ...]])
Returns a new dictionary-like object. :class:`defaultdict` is a subclass of the
``None``, if absent.
-.. _defaultdict-examples:
-
:class:`defaultdict` Examples
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[('blue', set([2, 4])), ('red', set([1, 3]))]
-.. _named-tuple-factory:
-
:func:`namedtuple` Factory Function for Tuples with Named Fields
----------------------------------------------------------------