summaryrefslogtreecommitdiffstats
path: root/Doc/library/collections.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r--Doc/library/collections.rst91
1 files changed, 47 insertions, 44 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 7827700..cff07b9 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -166,59 +166,60 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
where only the most recent activity is of interest.
-Deque objects support the following methods:
+ Deque objects support the following methods:
-.. method:: deque.append(x)
+ .. method:: append(x)
- Add *x* to the right side of the deque.
+ Add *x* to the right side of the deque.
-.. method:: deque.appendleft(x)
+ .. method:: appendleft(x)
- Add *x* to the left side of the deque.
+ Add *x* to the left side of the deque.
-.. method:: deque.clear()
+ .. method:: clear()
- Remove all elements from the deque leaving it with length 0.
+ Remove all elements from the deque leaving it with length 0.
-.. method:: deque.extend(iterable)
+ .. method:: extend(iterable)
- Extend the right side of the deque by appending elements from the iterable
- argument.
+ Extend the right side of the deque by appending elements from the iterable
+ argument.
-.. method:: deque.extendleft(iterable)
+ .. method:: extendleft(iterable)
- Extend the left side of the deque by appending elements from *iterable*. Note,
- the series of left appends results in reversing the order of elements in the
- iterable argument.
+ Extend the left side of the deque by appending elements from *iterable*.
+ Note, the series of left appends results in reversing the order of
+ elements in the iterable argument.
-.. method:: deque.pop()
+ .. method:: pop()
- Remove and return an element from the right side of the deque. If no elements
- are present, raises an :exc:`IndexError`.
+ Remove and return an element from the right side of the deque. If no
+ elements are present, raises an :exc:`IndexError`.
-.. method:: deque.popleft()
+ .. method:: popleft()
- Remove and return an element from the left side of the deque. If no elements are
- present, raises an :exc:`IndexError`.
+ Remove and return an element from the left side of the deque. If no
+ elements are present, raises an :exc:`IndexError`.
-.. method:: deque.remove(value)
+ .. method:: remove(value)
- Removed the first occurrence of *value*. If not found, raises a
- :exc:`ValueError`.
+ Removed the first occurrence of *value*. If not found, raises a
+ :exc:`ValueError`.
-.. method:: deque.rotate(n)
+ .. method:: rotate(n)
+
+ Rotate the deque *n* steps to the right. If *n* is negative, rotate to
+ the left. Rotating one step to the right is equivalent to:
+ ``d.appendleft(d.pop())``.
- Rotate the deque *n* steps to the right. If *n* is negative, rotate to the
- left. Rotating one step to the right is equivalent to:
- ``d.appendleft(d.pop())``.
In addition to the above, deques support iteration, pickling, ``len(d)``,
``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with
@@ -348,32 +349,34 @@ in Unix::
arguments.
-:class:`defaultdict` objects support the following method in addition to the
-standard :class:`dict` operations:
+ :class:`defaultdict` objects support the following method in addition to the
+ standard :class:`dict` operations:
+
+ .. method:: defaultdict.__missing__(key)
-.. method:: defaultdict.__missing__(key)
+ If the :attr:`default_factory` attribute is ``None``, this raises an
+ :exc:`KeyError` exception with the *key* as argument.
- If the :attr:`default_factory` attribute is ``None``, this raises an
- :exc:`KeyError` exception with the *key* as argument.
+ If :attr:`default_factory` is not ``None``, it is called without arguments
+ to provide a default value for the given *key*, this value is inserted in
+ the dictionary for the *key*, and returned.
- If :attr:`default_factory` is not ``None``, it is called without arguments to
- provide a default value for the given *key*, this value is inserted in the
- dictionary for the *key*, and returned.
+ If calling :attr:`default_factory` raises an exception this exception is
+ propagated unchanged.
- If calling :attr:`default_factory` raises an exception this exception is
- propagated unchanged.
+ This method is called by the :meth:`__getitem__` method of the
+ :class:`dict` class when the requested key is not found; whatever it
+ returns or raises is then returned or raised by :meth:`__getitem__`.
- This method is called by the :meth:`__getitem__` method of the :class:`dict`
- class when the requested key is not found; whatever it returns or raises is then
- returned or raised by :meth:`__getitem__`.
-:class:`defaultdict` objects support the following instance variable:
+ :class:`defaultdict` objects support the following instance variable:
-.. attribute:: defaultdict.default_factory
+ .. attribute:: defaultdict.default_factory
- This attribute is used by the :meth:`__missing__` method; it is initialized from
- the first argument to the constructor, if present, or to ``None``, if absent.
+ This attribute is used by the :meth:`__missing__` method; it is
+ initialized from the first argument to the constructor, if present, or to
+ ``None``, if absent.
.. _defaultdict-examples: