[Python-ideas] Order of loops in list comprehension

Alexander Heger python at 2sn.net
Sat Oct 22 03:50:52 EDT 2016


>
>
>> For me the current behaviour does not seem unreasonable as it resembles
>>> the order in which you write out loops outside a comprehension
>>>
>>
>> That's true, but the main reason for having comprehensions
>> syntax in the first place is so that it can be read
>> declaratively -- as a description of the list you want,
>> rather than a step-by-step sequence of instructions for
>> building it up.
>>
>> If you have to stop and mentally transform it into nested
>> for-statements, that very purpose is undermined.
>>
> Exactly.


Well, an argument that was often brought up on this forum is that Python
should do things consistently, and not in one way in one place and in
another way in another place, for the same thing.  Here it is about the
order of loop execution.  The current behaviour in comprehension is that is
ts being done the same way as in nested for loops.  Which is easy enough to
remember.  Same way, everywhere.

-Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161022/8da45989/attachment.html>


More information about the Python-ideas mailing list