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

Andrew Barnert abarnert at yahoo.com
Fri Jul 3 05:20:33 CEST 2015

On Jul 2, 2015, at 03:17, Pierre Quentel <pierre.quentel at gmail.com> wrote:
> 2015-07-02 9:32 GMT+02:00 Andrew Barnert via Python-ideas <python-ideas at python.org>:
>> LOn Jul 2, 2015, at 00:12, Nathaniel Smith 
>> You can already do this with accumulate; you just have to write lambda x, _: x*2.
>> Of course it doesn't include the built-in bounds, but I don't think you'd want that anyway. With accumulate, you can bound on the domain by passing range instead of count for the input, bound on the range with takewhile, or generate an infinite iterator, or anything else you think might be useful.
>> Or one more of the various combinations of things you can trivially build out of these pieces might be useful as a recipe ("irange"?) and/or in the third-party more-iterools.
> I am not saying that you can't find other ways to get the same result, just that using a function (usually a lambda) is easier to code and to understand.

I don't understand how using a function is easier to code and understand than using a function. Or how passing it to range is any simpler than passing it to accumulate, or to a recipe function built on top of accumulate.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150702/6c814376/attachment.html>

More information about the Python-ideas mailing list