Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4229,6 +4229,29 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
value)`` pairs. Order comparisons ('<', '<=', '>=', '>') raise
:exc:`TypeError`.

Dict preserves insertion order. Note that updating key doesn't affects the
order. On the other hand, keys added after deletion are inserted to the
last. ::

>>> 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
Dict order is guaranteed to be insertion order. This behavior was
implementation detail of CPython from 3.6.

.. seealso::
:class:`types.MappingProxyType` can be used to create a read-only view
of a :class:`dict`.
Expand Down