"James Reynolds" <eire1...@gmail.com> wrote
Here's another idea I had. I thought this would be slower than then the
previous algorithm because it has another for loop and another while
loop. I
read that the overhead of such loops is high, so I have been trying to
avoid
using them where possible.
Thats often true but nested loops are sometimes unavoidable.
Its unnecessary nests that are really bad!
But the other important rule when tuning performamce is: don't guess,
measure.
Put the new design in and test it to see if it runs any faster. Ultimately
thats
the only thing that matters (assuming its giving the correct results of
course!)
def mcrange_gen(self, sample):
nx2 = self.nx1
for q in sample:
for a in nx2:
while a > q:
pass
yield a
break
You shouldn't need the break after the yield. The yield returns a value
and the loop iteration ends naturally.
Alan G.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor