Pyrex: step in for loop

Greg Ewing greg at cosc.canterbury.ac.nz
Fri May 27 00:50:57 EDT 2005


Luis P. Mendes wrote:

> I'm trying to improve speed in a module and substituted the pythonic
> 'for in range()' for 'for i from min < i < max:'
> 
> But, I need to define a step for the i variable.  How can I do it?

If you want maximum clarity, I'd suggest using the for-loop
to iterate over a contiguous range of integers and an expression
that maps the loop variable to whatever you want.

If you want the maximum possible speed, it *may* be faster
to use a while loop instead and do your own index updating.
But profile to make sure.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list