Skip to content
44 changes: 22 additions & 22 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4838,6 +4838,28 @@ can be used interchangeably to index the same dictionary entry.
Providing keyword arguments as in the first example only works for keys that
are valid Python identifiers. Otherwise, any valid keys can be used.

Dictionaries preserve insertion order. Note that updating a key does not
affect the order. Keys added after deletion are inserted at the end. ::

>>> d = {"one": 1, "two": 2, "three": 3, "four": 4}
>>> d
{'one': 1, 'two': 2, 'three': 3, 'four': 4}
>>> list(d)
['one', 'two', 'three', 'four']
>>> list(d.values())
[1, 2, 3, 4]
>>> d["one"] = 42
>>> d
{'one': 42, 'two': 2, 'three': 3, 'four': 4}
>>> del d["two"]
>>> d["two"] = None
>>> d
{'one': 42, 'three': 3, 'four': 4, 'two': None}

.. versionchanged:: 3.7
Dictionary order is guaranteed to be insertion order. This behavior was
an implementation detail of CPython from 3.6.


These are the operations that dictionaries support (and therefore, custom
mapping types should support too):
Expand Down Expand Up @@ -5012,28 +5034,6 @@ can be used interchangeably to index the same dictionary entry.
value)`` pairs (regardless of ordering). Order comparisons ('<', '<=', '>=', '>') raise
:exc:`TypeError`.

Dictionaries preserve insertion order. Note that updating a key does not
affect the order. Keys added after deletion are inserted at the end. ::

>>> d = {"one": 1, "two": 2, "three": 3, "four": 4}
>>> d
{'one': 1, 'two': 2, 'three': 3, 'four': 4}
>>> list(d)
['one', 'two', 'three', 'four']
>>> list(d.values())
[1, 2, 3, 4]
>>> d["one"] = 42
>>> d
{'one': 42, 'two': 2, 'three': 3, 'four': 4}
>>> del d["two"]
>>> d["two"] = None
>>> d
{'one': 42, 'three': 3, 'four': 4, 'two': None}

.. versionchanged:: 3.7
Dictionary order is guaranteed to be insertion order. This behavior was
an implementation detail of CPython from 3.6.

Dictionaries and dictionary views are reversible. ::

>>> d = {"one": 1, "two": 2, "three": 3, "four": 4}
Expand Down
Loading