[Python-ideas] A conditional "for" statement

Michael S. Gilbert michael.s.gilbert at gmail.com
Fri Apr 24 01:07:07 CEST 2009

On Thu, 23 Apr 2009 18:56:28 -0400, Terry Reedy wrote:
> Proposed and rejected.
> The difference between
> for i in seq:
>    if p(i):
>      do(i)
> and
> for i in seq if p(i):
>    do(i)
> is deletion of ':\n'.  Hardly worth the bother.

What about the difference in efficiency?  For the second case, you've
reduced the number of iterations (by the number of items that your
conditional expression has excluded) and eliminated one operation per
iteration (evaluation the if statement).


More information about the Python-ideas mailing list