Skip to content

Commit 90384e6

Browse files
committed
bpo-32337: Update tutorial for dict order, since Python 3.7 order of dict is now guaranteed.
1 parent 4f4ef0a commit 90384e6

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

Doc/tutorial/datastructures.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ You can't use lists as keys, since lists can be modified in place using index
497497
assignments, slice assignments, or methods like :meth:`append` and
498498
:meth:`extend`.
499499

500-
It is best to think of a dictionary as an unordered set of *key: value* pairs,
500+
It is best to think of a dictionary as a set of *key: value* pairs,
501501
with the requirement that the keys are unique (within one dictionary). A pair of
502502
braces creates an empty dictionary: ``{}``. Placing a comma-separated list of
503503
key:value pairs within the braces adds initial key:value pairs to the
@@ -509,26 +509,26 @@ pair with ``del``. If you store using a key that is already in use, the old
509509
value associated with that key is forgotten. It is an error to extract a value
510510
using a non-existent key.
511511

512-
Performing ``list(d.keys())`` on a dictionary returns a list of all the keys
513-
used in the dictionary, in arbitrary order (if you want it sorted, just use
514-
``sorted(d.keys())`` instead). [2]_ To check whether a single key is in the
512+
Performing ``list(d)`` on a dictionary returns a list of all the keys
513+
used in the dictionary, in insertion order (if you want it sorted, just use
514+
``sorted(d)`` instead). [2]_ To check whether a single key is in the
515515
dictionary, use the :keyword:`in` keyword.
516516

517517
Here is a small example using a dictionary::
518518

519519
>>> tel = {'jack': 4098, 'sape': 4139}
520520
>>> tel['guido'] = 4127
521521
>>> tel
522-
{'sape': 4139, 'guido': 4127, 'jack': 4098}
522+
{'jack': 4098, 'sape': 4139, 'guido': 4127}
523523
>>> tel['jack']
524524
4098
525525
>>> del tel['sape']
526526
>>> tel['irv'] = 4127
527527
>>> tel
528-
{'guido': 4127, 'irv': 4127, 'jack': 4098}
529-
>>> list(tel.keys())
530-
['irv', 'guido', 'jack']
531-
>>> sorted(tel.keys())
528+
{'jack': 4098, 'guido': 4127, 'irv': 4127}
529+
>>> list(tel)
530+
['jack', 'guido', 'irv']
531+
>>> sorted(tel)
532532
['guido', 'irv', 'jack']
533533
>>> 'guido' in tel
534534
True
@@ -539,7 +539,7 @@ The :func:`dict` constructor builds dictionaries directly from sequences of
539539
key-value pairs::
540540

541541
>>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
542-
{'sape': 4139, 'jack': 4098, 'guido': 4127}
542+
{'sape': 4139, 'guido': 4127, 'jack': 4098}
543543

544544
In addition, dict comprehensions can be used to create dictionaries from
545545
arbitrary key and value expressions::
@@ -551,7 +551,7 @@ When the keys are simple strings, it is sometimes easier to specify pairs using
551551
keyword arguments::
552552

553553
>>> dict(sape=4139, guido=4127, jack=4098)
554-
{'sape': 4139, 'jack': 4098, 'guido': 4127}
554+
{'sape': 4139, 'guido': 4127, 'jack': 4098}
555555

556556

557557
.. _tut-loopidioms:

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,7 @@ Ian Seyer
14391439
Dmitry Shachnev
14401440
Anish Shah
14411441
Daniel Shahaf
1442+
Hui Shang
14421443
Mark Shannon
14431444
Ha Shao
14441445
Richard Shapiro
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update tutorial for ``dict`` order, since Python 3.7 order of dict is now guaranteed.

0 commit comments

Comments
 (0)