mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Add doctest and improve readability for move_to_end() example. (#30370)
This commit is contained in:
parent
51700bf08b
commit
770f43d47e
1 changed files with 5 additions and 3 deletions
|
@ -1120,14 +1120,16 @@ Some differences from :class:`dict` still remain:
|
|||
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::
|
||||
not exist:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> d = OrderedDict.fromkeys('abcde')
|
||||
>>> d.move_to_end('b')
|
||||
>>> ''.join(d.keys())
|
||||
>>> ''.join(d)
|
||||
'acdeb'
|
||||
>>> d.move_to_end('b', last=False)
|
||||
>>> ''.join(d.keys())
|
||||
>>> ''.join(d)
|
||||
'bacde'
|
||||
|
||||
.. versionadded:: 3.2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue