[Python-ideas] A conditional "for" statement

Bruce Leban bruce at leapyear.org
Fri Apr 24 01:19:13 CEST 2009


what makes you think that this would be more efficient? If it was
significant, surely the compiler could detect the for/if idiom and optimize
it.

On Thu, Apr 23, 2009 at 4:07 PM, Michael S. Gilbert <
michael.s.gilbert at gmail.com> wrote:

> On Thu, 23 Apr 2009 18:56:28 -0400, Terry Reedy wrote:
> > 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).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090423/d763c185/attachment.html>


More information about the Python-ideas mailing list