a break for comprehensions

Peter Hansen peter at engcorp.com
Fri Jul 27 00:09:16 EDT 2001


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.

(I'm quite sure in time list comprehensions will be quite
readable to me.  Eventually even Perl can become readable
to someone.  That doesn't mean the meaning of either is
obvious to a newcomer, which is what bothers me about both.)

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list