[Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

David Mertz mertz at gnosis.cx
Sun Oct 23 12:22:42 EDT 2016


On Oct 23, 2016 9:12 AM, "Danilo J. S. Bellini" <danilo.bellini at gmail.com>
wrote:
Actually, itertools.accumulate and functools.reduce have their parameters
reversed, and accumulate doesn't have a "start" parameter.

def accumulate2(fn=operator.add, it, start=None):
    if start is not None:
         it = iterations.chain([start], it)
    return itertools.accumulate(it, fn)

I would have preferred this signature to start with, but it's easy to wrap.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161023/8f9c2aec/attachment.html>


More information about the Python-ideas mailing list