<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-07-03 12:23 GMT+02:00 Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On Fri, Jul 3, 2015 at 8:10 PM, Pierre Quentel <<a href="mailto:pierre.quentel@gmail.com">pierre.quentel@gmail.com</a>> wrote:<br>
> 2015-07-03 11:54 GMT+02:00 Peter Otten <__<a href="mailto:peter__@web.de">peter__@web.de</a>>:<br>
>><br>
>> Pierre Quentel wrote:<br>
>><br>
>> > With the proposed Range class, here is an implementation of the<br>
>> > Fibonacci<br>
>> > sequence, limited to 2000 :<br>
>> ><br>
>> > previous = 0<br>
>> > def fibo(last):<br>
>> >     global previous<br>
>> >     _next, previous = previous+last, last<br>
>> >     return _next<br>
>> ><br>
>> > print(list(Range(1, 2000, fibo)))<br>
>><br>
>> How would you make<br>
>><br>
>> print(list(Range(1000, 2000, fibo)))<br>
>><br>
>> work?<br>
><br>
><br>
> I wouldn't, the Fibonacci sequence starts with (0, 1), not with (0, 1000)<br>
<br>
</span>The whole numbers start with (0, 1) too (pun intended), but you can<br>
ask for a range that starts part way into that sequence:<br>
<br>
>>> list(range(10,20))<br>
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]<br>
<br>
You can create "chunked ranges" by simply migrating your previous<br>
second argument into your new first argument, and picking a new second<br>
argument. Or you can handle an HTTP parameter "?page=4" by multiplying<br>
4 by your chunk size and using that as your start, adding another<br>
chunk and making that your end. While it's fairly easy to ask for<br>
Fibonacci numbers up to 2000, it's rather harder to ask for only the<br>
ones 1000 and greater. </blockquote><div><br></div><div>No, that's very easy, just rewrite the function :<br><br>previous = 987<br>def fibo(last):<br>    global previous<br>    _next, previous = previous+last, last<br>    return _next<br><br>print(list(Range(1597, 10000, fibo)))<br><br></div><div>and erase the browser history ;-)<br><br></div><div>More seriously, you can't produce this sequence without starting by the first 2 item (0, 1), no matter how you implement it<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Your range *must* start at the very beginning -<br>
a very good place to start, don't get me wrong, but it's a little<br>
restrictive if that's _all_ you can do.<br>
<br>
ChrisA<br>
<div class=""><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br></div></div>