Skip to content

Commit 6c9d217

Browse files
committed
move the explanation of dict equal before its use
1 parent 08d7687 commit 6c9d217

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Doc/library/stdtypes.rst

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4838,6 +4838,28 @@ can be used interchangeably to index the same dictionary entry.
48384838
Providing keyword arguments as in the first example only works for keys that
48394839
are valid Python identifiers. Otherwise, any valid keys can be used.
48404840

4841+
Dictionaries preserve insertion order. Note that updating a key does not
4842+
affect the order. Keys added after deletion are inserted at the end. ::
4843+
4844+
>>> d = {"one": 1, "two": 2, "three": 3, "four": 4}
4845+
>>> d
4846+
{'one': 1, 'two': 2, 'three': 3, 'four': 4}
4847+
>>> list(d)
4848+
['one', 'two', 'three', 'four']
4849+
>>> list(d.values())
4850+
[1, 2, 3, 4]
4851+
>>> d["one"] = 42
4852+
>>> d
4853+
{'one': 42, 'two': 2, 'three': 3, 'four': 4}
4854+
>>> del d["two"]
4855+
>>> d["two"] = None
4856+
>>> d
4857+
{'one': 42, 'three': 3, 'four': 4, 'two': None}
4858+
4859+
.. versionchanged:: 3.7
4860+
Dictionary order is guaranteed to be insertion order. This behavior was
4861+
an implementation detail of CPython from 3.6.
4862+
48414863

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

5015-
Dictionaries preserve insertion order. Note that updating a key does not
5016-
affect the order. Keys added after deletion are inserted at the end. ::
5017-
5018-
>>> d = {"one": 1, "two": 2, "three": 3, "four": 4}
5019-
>>> d
5020-
{'one': 1, 'two': 2, 'three': 3, 'four': 4}
5021-
>>> list(d)
5022-
['one', 'two', 'three', 'four']
5023-
>>> list(d.values())
5024-
[1, 2, 3, 4]
5025-
>>> d["one"] = 42
5026-
>>> d
5027-
{'one': 42, 'two': 2, 'three': 3, 'four': 4}
5028-
>>> del d["two"]
5029-
>>> d["two"] = None
5030-
>>> d
5031-
{'one': 42, 'three': 3, 'four': 4, 'two': None}
5032-
5033-
.. versionchanged:: 3.7
5034-
Dictionary order is guaranteed to be insertion order. This behavior was
5035-
an implementation detail of CPython from 3.6.
5036-
50375037
Dictionaries and dictionary views are reversible. ::
50385038

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

0 commit comments

Comments
 (0)