[Python-ideas] Pass a function as the argument "step" of range()
pierre.quentel at gmail.com
Thu Jul 2 17:53:06 CEST 2015
2015-07-02 17:23 GMT+02:00 Ethan Furman <ethan at stoneleaf.us>:
> 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.
It's true, but testing that an integer is a range is very rare : the
pattern "if X in range(Y)" is only found once in all the Python 3.4
standard library (in Lib/test/test_genexps.py), and "assert X in range(Y)"
nowhere, whereas "for X in range(Y)" is everywhere.
So even if __contains__ must iterate on all the items if the argument of
step() is a function, I don't see it as a big problem.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas