Skip to content

Commit ea0eeb8

Browse files
bpo-39879: Update datamodel docs to include dict ordering (GH-19006)
Co-authored-by: furkanonder <[email protected]> (cherry picked from commit 59c644e) Co-authored-by: Lahfa Samy <[email protected]>
1 parent 0dad748 commit ea0eeb8

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Doc/reference/datamodel.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ Mappings
420420
equal (e.g., ``1`` and ``1.0``) then they can be used interchangeably to index
421421
the same dictionary entry.
422422

423+
Dictionaries preserve insertion order, meaning that keys will be produced
424+
in the same order they were added sequentially over the dictionary.
425+
Replacing an existing key does not change the order, however removing a key
426+
and re-inserting it will add it to the end instead of keeping its old place.
427+
423428
Dictionaries are mutable; they can be created by the ``{...}`` notation (see
424429
section :ref:`dict`).
425430

@@ -431,6 +436,11 @@ Mappings
431436
additional examples of mapping types, as does the :mod:`collections`
432437
module.
433438

439+
.. versionchanged:: 3.7
440+
Dictionaries did not preserve insertion order in versions of Python before 3.6.
441+
In CPython 3.6, insertion order was preserved, but it was considered
442+
an implementation detail at that time rather than a language guarantee.
443+
434444
Callable types
435445
.. index::
436446
object: callable

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Ray Allen
3737
Billy G. Allie
3838
Jamiel Almeida
3939
Kevin Altis
40+
Samy Lahfa
4041
Skyler Leigh Amador
4142
Joe Amenta
4243
Rose Ames
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Updated :ref:`datamodel` docs to include :func:`dict` insertion order preservation.
2+
Patch by Furkan Onder and Samy Lahfa.

0 commit comments

Comments
 (0)