diff options
author | Raymond Hettinger <python@rcn.com> | 2010-09-06 21:26:09 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-09-06 21:26:09 (GMT) |
commit | f45abc97bfad3bc9737a8a8d95c1f4a60cd6f478 (patch) | |
tree | 7b24d9113c1d79480cde1daae9ed58199bc0e007 /Doc/library/collections.rst | |
parent | 7b2a7710ef17e38e021f6f045b8cd7ad0e96d5e1 (diff) | |
download | cpython-f45abc97bfad3bc9737a8a8d95c1f4a60cd6f478.zip cpython-f45abc97bfad3bc9737a8a8d95c1f4a60cd6f478.tar.gz cpython-f45abc97bfad3bc9737a8a8d95c1f4a60cd6f478.tar.bz2 |
Add method to OrderedDict for repositioning keys to the ends.
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r-- | Doc/library/collections.rst | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 454817b..1cc4097 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -793,6 +793,23 @@ the items are returned in the order their keys were first added. (key, value) pair. The pairs are returned in LIFO order if *last* is true or FIFO order if false. + .. method:: move_to_end(key, last=True) + + Move an existing *key* to either end of an ordered dictionary. The item + is moved to the right end if *last* is true (the default) or to the + beginning if *last* is false. Raises :exc:`KeyError` if the *key* does + not exist:: + + >>> d = OrderedDict.fromkeys('abcde') + >>> d.move_to_end('b') + >>> ''.join(d.keys) + 'acdeb' + >>> d.move_to_end('b', 0) + >>> ''.join(d.keys) + 'bacde' + + .. versionadded:: 3.2 + In addition to the usual mapping methods, ordered dictionaries also support reverse iteration using :func:`reversed`. |