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

Andrew Barnert abarnert at yahoo.com
Wed Aug 13 21:12:50 CEST 2014


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

> 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.

Have you ever heard of anyone wanting to "sum" a bunch of pieces of text? Or a bunch of lists?

Actually, now that I think about it, although I was being somewhat flippant, I've heard both of those things plenty of times, and never once has it meant concatenation. It always means literal or figurative element-wise summing, or some other kind of aggregation. Which makes it even _less_ obvious as a one true way to concatenate a bunch of things.

Also, how often do you really want to concatenate a bunch of lists into a bigger list, as opposed to just chaining them together into a new iterable? It's not _never_, but I think it's less common. So if itertools.chain.from_iterable doesn't deserve to be a builtin (or even a top-level module function), is concat, a modified sum, or some other way to spell the same idea really necessary?


More information about the Python-ideas mailing list