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: Tut: Dict used before dicts explained
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: fdrake, rhettinger, spiv
Priority: high Keywords:

Created on 2001-11-10 11:21 by spiv, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tut.diff rhettinger, 2002-06-25 03:41 tut.diff
Messages (4)
msg7503 - (view) Author: Andrew Bennetts (spiv) Date: 2001-11-10 11:21
This was pointed out to me by someone on #python, who
was rather confused by this...

In Section 5.1.4 of the Tutorial it has an example of a
list comprehension:
"""
>>> [{x: x**2} for x in vec]
[{2: 4}, {4: 16}, {6: 36}]
"""

But the "{x: x**2}" is confusing, because dictionaries
haven't been explained yet (that's Section 5.4).

This example either needs to be removed or modified. 
It is a good example of the sort of expression you can
use in a list comprehension, so I'd recommend adding an
comment referring the reader to Section 5.4, rather
than removing it.
msg7504 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-06-25 03:41
Logged In: YES 
user_id=80475

I think the example should be removed (patch attached) 
not only because of the forward reference, but because 
suggests that it is normal of construct lists of dictionaries.  

Were the dict constructor being introduced, a useful 
example would be:

>>> dict([(x, x**2) for x in vec])
{2: 4, 4: 16, 6: 36}
msg7505 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2002-06-25 13:20
Logged In: YES 
user_id=3066

Agreed; check in as patched.

Raymond, feel free to expand the introduction of
dictionaries to include the dict constructor.  ;-)  You're
on a roll!
msg7506 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-06-25 15:14
Logged In: YES 
user_id=80475

Added dict() constructor introduction.

Committed as tut.tex  1.165 and 1.156.4.1.2.4

Closing bug.
History
Date User Action Args
2022-04-10 16:04:37adminsetgithub: 35501
2001-11-10 11:21:00spivcreate