This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tutorial on dictionaries has error in example
Type: Stage: resolved
Components: Documentation Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.smith, tberla
Priority: normal Keywords:

Created on 2017-11-24 19:14 by tberla, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg306913 - (view) Author: Toby Berla (tberla) Date: 2017-11-24 19:14
in https://docs.python.org/3/tutorial/datastructures.html: 

-----
5.5. Dictionaries
...
Here is a small example using a dictionary:

>>>
>>> tel = {'jack': 4098, 'sape': 4139}
>>> tel['guido'] = 4127
>>> tel
{'sape': 4139, 'guido': 4127, 'jack': 4098}
-----

I think the order of dictionary elements shown after 'guido' is inserted is wrong.

The correct order is: 
{'jack': 4098, 'sape': 4139, 'guido': 4127}
msg306914 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-11-24 19:16
dict makes no guarantees on ordering, so I think the example is fine. There is no "correct" ordering.
msg306915 - (view) Author: Toby Berla (tberla) Date: 2017-11-24 19:25
Thanks, Eric. (I'm new to Python.) Perhaps I should have paid closer attention to the description of the dictionary data structure -- 

"Performing list(d.keys()) on a dictionary returns a list of all the keys used in the dictionary, in arbitrary order"

-- rather than just jumping ahead to the code example. ;-)
msg306932 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-11-25 01:42
No problem. Welcome to Python!
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76308
2017-11-25 01:42:56eric.smithsetmessages: + msg306932
2017-11-24 19:25:53tberlasetstatus: open -> closed
resolution: not a bug
messages: + msg306915

stage: resolved
2017-11-24 19:16:52eric.smithsetnosy: + eric.smith
messages: + msg306914
2017-11-24 19:14:29tberlacreate