[Python-ideas] Pass a function as the argument "step" of range()
Pierre Quentel
pierre.quentel at gmail.com
Fri Jul 3 12:10:22 CEST 2015
2015-07-03 11:54 GMT+02:00 Peter Otten <__peter__ at web.de>:
> 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?
I wouldn't, the Fibonacci sequence starts with (0, 1), not with (0, 1000)
> Without that and with the `previous` global under the rug that doesn't
> look range-like.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150703/53f22fa4/attachment.html>
More information about the Python-ideas
mailing list