[Python-ideas] Rehabilating reduce (as "fold")

Zachary Ware zachary.ware+pyideas at gmail.com
Fri Jul 12 22:48:41 CEST 2013


On Fri, Jul 12, 2013 at 2:32 PM, Brett Cannon <brett at python.org> wrote:
>
>
>
> On Fri, Jul 12, 2013 at 10:54 AM, Barry Warsaw <barry at python.org> wrote:
>>
>> On Jul 12, 2013, at 04:01 PM, Nick Coghlan wrote:
>>
>> >I'd personally be in favour of the notion of also allowing strings as the
>> >first argument, so you could instead write:
>> >
>> >    data = fold("+=", [], iterables)
>>
>> You had me until here...
>>
>> >(Independent of this idea, it would actually be nice if the operator
>> > module
>> >had a dictionary mapping from op symbols to names, like
>> >operator.by_symbol["+="] giving operator.iadd)
>>
>> ...but this is a neat idea.
>
>
> +1 from me as well. The table already exists in the docs
> (http://docs.python.org/3.4/library/operator.html#module-operator), it just
> needs to be codified. Maybe operator.map['+='] or
> operator.from_syntax['+=']. Go really nuts and support ['.attribute'] or
> ['[42]'] to auto-generate attrgetter or itemgetter instances, but that's
> probably just asking for support problems.
>

I decided to take a stab at this idea and thus created issue18436[1].

--
Zach

[1]http://bugs.python.org/issue18436


More information about the Python-ideas mailing list