
April 23, 2009
7:19 p.m.
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@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).