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

Peter Otten __peter__ at web.de
Fri Jul 3 11:54:28 CEST 2015


Pierre Quentel wrote:

> With the proposed Range class, here is an implementation of the Fibonacci
> sequence, limited to 2000 :
> 
> previous = 0
> def fibo(last):
>     global previous
>     _next, previous = previous+last, last
>     return _next
> 
> print(list(Range(1, 2000, fibo)))

How would you make

print(list(Range(1000, 2000, fibo)))

work? Without that and with the `previous` global under the rug that doesn't 
look range-like.




More information about the Python-ideas mailing list