a break for comprehensions

Paul Svensson paul at svensson.org
Fri Jul 27 10:22:41 EDT 2001


Peter Hansen <peter at engcorp.com> writes:

>Kevin Lacker wrote:
>>
>> How cryptic is
>> 
>> [process(x) for x in my_list while is_good(x)]
>> 
>> ? Not really any more cryptic than
>> 
>> [process(x) for x in my_list if is_good(x)]
>> 
>> which seems to be agreeably a good thing to have. I certainly like it.
>
>Assuming you can read the one, the other is at least as
>readable.
>
>In my post I was attempting to point out that I find list 
>comprehensions less readable than the equivalent, longer but 
>more explicit while loop version, not that one list comprehension 
>is more or less cryptic than another.

In my mind, the most important difference between a list comprehension
and the explicit loop replacement, is that the latter distracts my attention
away from the data going into the list, focusing too much on the process
of putting it there.

	/Paul



More information about the Python-list mailing list