Roundup Robot added the comment:
New changeset 84895d037258 by R David Murray in branch '3.4':
#21739: mention subtle difference between loops and listcomps in tutorial.
https://hg.python.org/cpython/rev/84895d037258
New changeset 8279017436a2 by R David Murray in branch 'default':
Merge
R. David Murray added the comment:
The only demure I got on this was from Ezio, who objected that the concept of
'scope' hadn't been introduced yet in the tutorial. So I reworded it to avoid
the word 'scope'.
Thanks, Rose.
--
resolution: - fixed
stage: commit review - resolved
Rose Ames added the comment:
Fwiw, I've seen a beginner be confused by this. Patch attached.
--
keywords: +patch
nosy: +superluser
Added file: http://bugs.python.org/file36593/reword.patch
___
Python tracker rep...@bugs.python.org
R. David Murray added the comment:
Thanks!
While this patch does sort-of go into a detail, it seems to me like it does it
in a tutorial-appropriate fashion. I'm +1 on applying this.
--
stage: needs patch - commit review
___
Python tracker
Ezio Melotti added the comment:
If we don't want to go into the details of why it's not equivalent, using
roughly equivalent might be enough.
--
keywords: +easy
nosy: +ezio.melotti
stage: - needs patch
type: - enhancement
___
Python tracker
Changes by Raymond Hettinger raymond.hettin...@gmail.com:
--
assignee: rhettinger - r.david.murray
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21739
___
New submission from Karl Richter:
It would be useful to have a short statement in the docs
(https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions)
that the expression in a list comprehension isn't put into a block, but
evaluated against the same block where it is located
R. David Murray added the comment:
In 3.x a list comprehension (like a generator expression in 2.x) *is* a
separate block:
[x for x in range(3)]
[0, 1, 2]
x
Traceback (most recent call last):
File stdin, line 1, in module
NameError: name 'x' is not defined
I note that this is not in fact
Raymond Hettinger added the comment:
I wouldn't like to use the tutorial to highlight or draw attention a
feature/bug that is going away.
I recommend leaving the tutorial as-is. For a decade, it has worked well for
introducing people to list comprehensions. More complete implementation
R. David Murray added the comment:
OK, I have no objection to leaving the 2.7 tutorial alone. It seems to me that
the 3.x tutorial should be fixed, though, because it currently says the
unrolled loop is equivalent, but it isn't. The fact that this applies to all
other comprehensions in
10 matches
Mail list logo