[Python-ideas] reduce(func, seq, initial=0)

Nick Coghlan ncoghlan at gmail.com
Fri Oct 10 12:27:01 CEST 2014


On 10 Oct 2014 20:07, "Chris Angelico" <rosuav at gmail.com> wrote:
>
> On Fri, Oct 10, 2014 at 8:11 PM, Stephan Sahm <Stephan.Sahm at gmx.de> wrote:
> > I stumbled upon the builtin reduce function. It has an optional
parameter
> > initial, however if trying to set it like
> >
> > import operator as op
> > reduce(op.add, range(10), initial=0)
> >
> > I get
> >
> > TypeError: reduce() takes no keyword arguments
> >
> >
> > I think it would be really straightforward to also add keyword
> > possibilities, at least to the parameter initial.
>
> The first thing to note is that reduce(), in Python 3, is now imported
> from functools; if you're working with Python 2, you won't see this
> changed unless you can convince people that this is a bug to be fixed.
> However, prefixing your code with "from functools import reduce"
> produces the exact same result in Python 3.
>
> The question is, though: What's the advantage? The first two arguments
> are mandatory, and there's only one optional argument. Do you need to
> say "initial=" on that?

Converting functools to argument clinic for 3.5 should fix it. I don't
believe anyone has tackled that yet.

Cheers,
Nick.

>
> ChrisA
> _______________________________________________
> 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/20141010/9e983973/attachment.html>


More information about the Python-ideas mailing list