summaryrefslogtreecommitdiffstats
path: root/Doc/library/collections.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-03-02 21:24:57 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-03-02 21:24:57 (GMT)
commit2d32f63ec9bef3c78144557e5b2984f9b56a3294 (patch)
tree4d78d308a592c20c62e416dea5382e247fd00794 /Doc/library/collections.rst
parent57b46f5b0ed0314c3733b96e6ce2f99d526db4ed (diff)
downloadcpython-2d32f63ec9bef3c78144557e5b2984f9b56a3294.zip
cpython-2d32f63ec9bef3c78144557e5b2984f9b56a3294.tar.gz
cpython-2d32f63ec9bef3c78144557e5b2984f9b56a3294.tar.bz2
PEP 372: OrderedDict()
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r--Doc/library/collections.rst29
1 files changed, 28 insertions, 1 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index c28704b..e4ad5f4 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -14,7 +14,7 @@
__name__ = '<doctest>'
This module implements high-performance container datatypes. Currently,
-there are three datatypes, :class:`Counter`, :class:`deque` and
+there are four datatypes, :class:`Counter`, :class:`deque`, :class:`OrderedDict` and
:class:`defaultdict`, and one datatype factory function, :func:`namedtuple`.
The specialized containers provided in this module provide alternatives
@@ -806,6 +806,33 @@ and more efficient to use a simple class declaration:
adapted for Python 2.4.
+:class:`OrderedDict` objects
+----------------------------
+
+Ordered dictionaries are just like regular dictionaries but they remember the
+order that items were inserted. When iterating over an ordered dictionary,
+the items are returned in the order their keys were first added.
+
+.. class:: OrderedDict([items])
+
+ Return an instance of a dict subclass, supporting the usual :class:`dict`
+ methods. An *OrderedDict* is a dict that remembers the order that keys
+ were first inserted. If a new entry overwrites an existing entry, the
+ original insertion position is left unchanged. Deleting an entry and
+ reinserting it will move it to the end.
+
+ .. versionadded:: 2.7
+
+The :meth:`popitem` method for ordered dictionaries returns and removes the
+last added entry. The key/value pairs are returned in LIFO order.
+
+Equality tests between :class:`OrderedDict` objects are order-sensitive
+and are implemented as ``list(od1.items())==list(od2.items())``.
+Equality tests between :class:`OrderedDict` objects and other
+:class:`Mapping` objects are order-insensitive like regular dictionaries.
+This allows :class:`OrderedDict` objects to be substituted anywhere a
+regular dictionary is used.
+
:class:`UserDict` objects
-------------------------