Re: "For" loop and list comprehension similarity
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: "For" loop and list comprehension similarity

From: Terry Reedy <tjreedy@udel.edu>
Date: Tue Mar 28 2006 - 00:34:07 CEST

"Peter Hansen" <peter@engcorp.com> wrote in message
news:e08r7a$4b5$1@sea.gmane.org...
> s.lipnevich@gmail.com wrote:
>> Do you think this discussion is a proof that the following principle
>> got violated, or do you think that "loop with condition" is not such an
>> atomic thing to be subject to this: "There should be one -- and
>> preferably only one -- obvious way to do it."
>
> Mitja's suggestion was the one obvious way. The others are all
> interesting, maybe even preferable in some cases, but I don't think most
> experienced Python programmers would be more likely to start with one of
> them than with the simple for-loop-with-explicit-test.

If by 'explicit-test' you mean a nested if-statement, then I agree. When I
mentioned filter() as one way to avoid the obvious, I was aware that it
creates an intermediate list that is usually not needed. (And if it is
needed, then it should be name-assigned before the loop.)

Terry Jan Reedy
Received on Sun Apr 30 21:21:57 2006