<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-07-03 11:56 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 5:30 PM, Pierre Quentel <<a href="mailto:pierre.quentel@gmail.com">pierre.quentel@gmail.com</a>> wrote:<br>
> With the proposed Range class, here is an implementation of the 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>
</span>Without the proposed Range class, here's an equivalent that doesn't<br>
use global state:<br>
<br>
def fibo(top):<br>
    a, b = 0, 1<br>
    while a < 2000:<br>
        yield a<br>
        a, b = a + b, a<br>
<br>
print(list(fibo(2000)))<br>
<br>
I'm not seeing this as an argument for a variable-step range<br>
func/class, especially since you need to use a global - or to<br>
construct a dedicated callable whose sole purpose is to maintain one<br>
integer of state. Generators are extremely expressive and flexible.<br></blockquote><div><br>Of course there are lots of ways to produce the Fibonacci sequence, and generators are perfect for this purpose. This was intended as an example of how to use the proposed range() with always the same logic : build a sequence of integers from a starting point, use a function to build the next item, and stop when a "stop" value is reached. <br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<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>