[Python-ideas] Pass a function as the argument "step" of range()

Ethan Furman ethan at stoneleaf.us
Thu Jul 2 17:23:05 CEST 2015

On 07/02/2015 08:16 AM, Pierre Quentel wrote:

> Again, this does not address the original problem : it produces the first 10 squares of 2, not the squares of 2 lower than a "stop" value.
> The logic of range(start, stop, step) is to produce the integers starting at "start", incremented by "step", until the integer is >= "stop" (or <= stop if stop<start).

The other logic of range is to be able to say:

   some_value in range(start, stop, step)

If step is an integer it is easy to calculate whether some_value is in the range; if step is a function, it becomes impossible to figure out without iterating through (possibly all) the values of range.


More information about the Python-ideas mailing list