[docs] [issue13549] Incorrect nested list comprehension documentation
report at bugs.python.org
Thu Dec 8 17:31:54 CET 2011
Éric Araujo <merwok at netwok.org> added the comment:
I welcome improvements to this part of the docs. Nested list comps had me quite confused at first: I had to write and execute them to understand how it worked. So, the patch looks good to me. Remarks:
- I’d recommend a few whitespace beautifications, like in ``for x in [1,2,3]`` and ``range(1,6)``.
- You changed “If the expression would evaluate to a tuple, it must be parenthesized” to “If the expression is a tuple (e.g. the ``(x, y)`` +in this example), it must be parenthesized”, I guess because either the concept that an expression evaluates to something is (a) incorrect or (b) not appropriate at this stage of the tutorial. I think there is an example that makes that line more understandable, but it’s in the section about tuples, not here in the listcomp section; you may or may not want to improve that too.
- +1 for the removal of the half-joking half-recommendation not to use nested list comps (“If you've got the stomach for it, list comprehensions can be nested. They are a powerful tool but -- like all powerful tools -- they need to be used carefully, if at all.”).
- Maybe a link to the itertools module is appropriate (either after the combinations example, or after the link to the built-in zip function).
Python tracker <report at bugs.python.org>
More information about the docs