<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jan 9, 2015 at 12:28 PM, M.-A. Lemburg <span dir="ltr"><<a href="mailto:mal@egenix.com" target="_blank">mal@egenix.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="HOEnZb"><div class="h5">On 09.01.2015 12:01, Chris Angelico wrote:<br>
> On Fri, Jan 9, 2015 at 9:55 PM, M.-A. Lemburg <<a href="mailto:mal@egenix.com">mal@egenix.com</a>> wrote:<br>
>>> This is what I am talking about.  The idea would be to have something that<br>
>>> is, as much as possible, identical to the existing range.  I understand it<br>
>>> has floating-point issues, but any other approach would as well.<br>
>><br>
>> This should do the trick:<br>
>><br>
>> def frange(start, stop, steps):<br>
>>     start = float(start)<br>
>>     stop = float(stop)<br>
>>     steps = int(steps)<br>
>>     for i in range(steps + 1):<br>
>>         yield ((steps - i) * start + i * stop) / steps<br>
><br>
> Thing is, a range object is a lot more than just an iterable. In many<br>
> ways, it acts just like list(self) would - you can index it, slice it,<br>
> etc:<br>
><br>
>>>> r = range(10, 101, 10)<br>
>>>> list(r)<br>
> [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]<br>
>>>> r.index(70)<br>
> 6<br>
>>>> r[6]<br>
> 70<br>
>>>> len(r)<br>
> 10<br>
>>>> r[1:-4:2]<br>
> range(20, 70, 20)<br>
><br>
> Does frange() need to be able to do all these operations?<br></div></div>
<snip><br><div>
IMO, the only reason for having an frange() function in (probably)<br>
the math module is to provide an implementation which tries to<br>
reduce fp rounding problems to a minimum.<br>
<br>
Other than that, it's just too simple to add straight to the<br>
application code in a way which exactly fits the purpose and<br>
functionality needed by that application. <br>
<span class="im HOEnZb"></span><br></div></blockquote><div><br></div><div>I think the wide usage of numpy.arange and numpy.linspace is evidence against that conclusion.<br></div></div><br></div></div>