diff options
author | Raymond Hettinger <python@rcn.com> | 2009-03-02 22:28:31 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-03-02 22:28:31 (GMT) |
commit | a4f52b12d6e401f14f3c8e9e2d533eb448388bcc (patch) | |
tree | eaac9d0f1fdd03665b04536ec28310846ade7f49 /Doc/library/collections.rst | |
parent | b62ad24cd8a166d0d87068ac6c6ed7fc83613f92 (diff) | |
download | cpython-a4f52b12d6e401f14f3c8e9e2d533eb448388bcc.zip cpython-a4f52b12d6e401f14f3c8e9e2d533eb448388bcc.tar.gz cpython-a4f52b12d6e401f14f3c8e9e2d533eb448388bcc.tar.bz2 |
Add OrderedDict support to collections.namedtuple().
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r-- | Doc/library/collections.rst | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 2a3445c..5d68e5a 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -651,9 +651,9 @@ Example: def __repr__(self): return 'Point(x=%r, y=%r)' % self <BLANKLINE> - def _asdict(t): - 'Return a new dict which maps field names to their values' - return {'x': t[0], 'y': t[1]} + def _asdict(self): + 'Return a new OrderedDict which maps field names to their values' + return OrderedDict(zip(self._fields, self)) <BLANKLINE> def _replace(self, **kwds): 'Return a new Point object replacing specified fields with new values' @@ -711,10 +711,14 @@ field names, the method and attribute names start with an underscore. .. method:: somenamedtuple._asdict() - Return a new dict which maps field names to their corresponding values:: + Return a new :class:`OrderedDict` which maps field names to their corresponding + values:: >>> p._asdict() - {'x': 11, 'y': 22} + OrderedDict([('x', 11), ('y', 22)]) + + .. versionchanged 3.1 + Returns an :class:`OrderedDict` instead of a regular :class:`dict`. .. method:: somenamedtuple._replace(kwargs) |