Skip to content

Commit 59c644e

Browse files
bpo-39879: Update datamodel docs to include dict ordering (GH-19006)
Co-authored-by: furkanonder <[email protected]>
1 parent 1b6b0e7 commit 59c644e

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
@@ -425,6 +425,11 @@ Mappings
425425
equal (e.g., ``1`` and ``1.0``) then they can be used interchangeably to index
426426
the same dictionary entry.
427427

428+
Dictionaries preserve insertion order, meaning that keys will be produced
429+
in the same order they were added sequentially over the dictionary.
430+
Replacing an existing key does not change the order, however removing a key
431+
and re-inserting it will add it to the end instead of keeping its old place.
432+
428433
Dictionaries are mutable; they can be created by the ``{...}`` notation (see
429434
section :ref:`dict`).
430435

@@ -436,6 +441,11 @@ Mappings
436441
additional examples of mapping types, as does the :mod:`collections`
437442
module.
438443

444+
.. versionchanged:: 3.7
445+
Dictionaries did not preserve insertion order in versions of Python before 3.6.
446+
In CPython 3.6, insertion order was preserved, but it was considered
447+
an implementation detail at that time rather than a language guarantee.
448+
439449
Callable types
440450
.. index::
441451
object: callable

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Ray Allen
3939
Billy G. Allie
4040
Jamiel Almeida
4141
Kevin Altis
42+
Samy Lahfa
4243
Skyler Leigh Amador
4344
Joe Amenta
4445
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)