[Python-ideas] if-syntax for regular for-loops

Arnaud Delobelle arnodel at googlemail.com
Fri Oct 3 14:00:50 CEST 2008


2008/10/3 Andreas Nilsson <adde at trialcode.com>:
> Hi.
> I'm reposting this here after erroneously posting it on python-dev.
>
> I use list comprehensions and generator expressions a lot and lately I've
> found myself writing a lot of code like this:
>
> for i in items if i.some_field == some_value: i.do_something()

I'm pretty sure this has been proposed before and that the consensus
was that there was no advantage to writing:

    for i in L if cond:
        action()

instead of:

     for i in L:
        if cond: action()

-- 
Arnaud



More information about the Python-ideas mailing list