[Python-bugs-list] [ python-Bugs-605047 ] Tutorial and list comprehension scope

noreply@sourceforge.net noreply@sourceforge.net
Fri, 06 Sep 2002 06:30:47 -0700


Bugs item #605047, was opened at 2002-09-05 08:10
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=605047&group_id=5470

Category: Documentation
>Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: John J Lee (jjlee)
>Assigned to: Raymond Hettinger (rhettinger)
Summary: Tutorial and list comprehension scope

Initial Comment:
I just made an expensive mistake with a list comprehension:

val = mean(vals)
bad_vals = sum([val < 0.0 or val > 1.0 for val in vals])

val gets clobbered by the list comprehension, silently messing
up my statistics.

Shouldn't there be a mention of this behaviour in the tutorial
(section 5.1.4, or in the part of section 9 on scope)?


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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-09-06 08:30

Message:
Logged In: YES 
user_id=80475

I'll add a note to the tutorial because this has surprised 
my than one person.   Using xbar as a variable name 
would've avoided the problem, but I digress.



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

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