[Python-ideas] sum(...) limitation

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Aug 13 20:29:29 CEST 2014


On Wed, Aug 13, 2014 at 2:03 PM, Antoine Pitrou <antoine at python.org> wrote:

> Le 13/08/2014 12:37, Steven D'Aprano a écrit :
>
>
>> sum() is *not* the One Obvious Way to add arbitrary objects in every
>> domain.
>>
>
> Well, it is. It's a builtin and it's called "sum", which makes it pretty
> clear it adds objects together. That could hardly be any more obvious,
> actually: all competitors are *less* obvious.
>

When it comes to "adding" sequences or containers, "concat" would be a
strong competitor.  After all, this is exactly what + does on sequences
under the hood. [1]

While there are technical reasons for reusing the same infix operator for
adding and concatenation, we are not so restricted when it comes to
builtins.

[1] https://docs.python.org/2/c-api/sequence.html#PySequence_Concat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140813/f2c6dd3c/attachment.html>


More information about the Python-ideas mailing list