Pyrex: step in for loop

Mike Meyer mwm at mired.org
Thu May 26 18:04:53 EDT 2005


"Luis P. Mendes" <luis_lupe2XXX at netvisaoXXX.pt> writes:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> 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?
>
> for example, how do I iterate through 80000 to 140000 with step 10000?

guru% pydoc range
Help on built-in function range in module __builtin__:

range(...)
    range([start,] stop[, step]) -> list of integers
    
    Return a list containing an arithmetic progression of integers.
    range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
    When step is given, it specifies the increment (or decrement).
    For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!
    These are exactly the valid indices for a list of 4 elements.

so it's

for i in range(80000, 140000, 10000): ...

    <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list