list comprehension question

alex23 wuwei23 at gmail.com
Wed May 6 03:20:29 EDT 2009


On May 6, 2:10 pm, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:
> It's precisely the indentation and colons (plus newlines) that makes
> nested for-loops easier to read than list-comps with multiple fors.
>
> You can get back *nearly* all the readability by splitting the list comp
> into multiple lines:

It was less the overall readability I was commenting on, and more the
claim that the listcomp required a 'back-and-forth' parsing to
understand. As you've reinforced, the listcomp can be readily
converted back to the multiple-line form by the inclusion of colons &
EOL markers, which means you can make as much sequential sense from a
listcomp as you can a for-loop.



More information about the Python-list mailing list