[Python-bugs-list] [ python-Bugs-480337 ] Tut: Dict used before dicts explained

noreply@sourceforge.net noreply@sourceforge.net
Tue, 25 Jun 2002 08:14:08 -0700


Bugs item #480337, was opened at 2001-11-10 06:21
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=480337&group_id=5470

Category: Documentation
Group: None
>Status: Closed
Resolution: Accepted
Priority: 6
Submitted By: Andrew Bennetts (spiv)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Tut: Dict used before dicts explained

Initial Comment:
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.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-06-25 10:14

Message:
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.


----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-06-25 08:20

Message:
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!

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-06-24 22:41

Message:
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}

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=480337&group_id=5470