List comprehension timing difference.

ting at thsu.org ting at thsu.org
Fri Sep 2 16:50:24 CEST 2011


On Sep 2, 9:54 am, Bart Kastermans <bkast... at gmail.com> wrote:
> if d(a,b) == 1 and a < b:

It will probably be faster if you reverse the evaluation order of that
expression.

if a<b and d(a,b)==1:

That way the d() function is called less than half the time. Of course
this assumes that a<b is a faster evaluation than d(a,b), but I think
that's true for your example.
--
// T.Hsu



More information about the Python-list mailing list