[Python-ideas] Add nullifier argument to functools.reduce?

Chris Angelico rosuav at gmail.com
Mon Aug 25 02:05:27 CEST 2014


On Sun, Aug 24, 2014 at 2:27 AM, Warren Weckesser
<warren.weckesser at gmail.com> wrote:
> That wouldn't help in an example such as
>
>     reduce(lambda x, y: x & y, [{1,2}, {3, 4}, {5, 6}], nullifier={})
>
> The nullifier is the empty set, but the empty set does not occur in the
> iterable.

Caution: Your nullifier is an empty dict, not an empty set, if you
spell it that way.

I think this is a cute concept, but not something that is going to be
needed all that often. Most Python programs don't even use reduce() in
its default form, much less need a specific optimization.

ChrisA


More information about the Python-ideas mailing list