[Python-ideas] Fast sum() for non-numbers
Ron Adam
ron3200 at gmail.com
Fri Jul 5 18:22:25 CEST 2013
On 07/03/2013 07:43 AM, Steven D'Aprano wrote:
>
> I'm not sure that sum() is the Obvious Way to concatenate lists, and I
> don't think that concatenating many lists is a common thing to do.
> Traditionally, sum() works only on numbers, and I think we wouldn't be
> having this discussion if Python used & for concatenation instead of +. So
> I don't care that sum() has quadratic performance on lists (and tuples),
> and I must admit that having a simple quadratic algorithm in the built-ins
> is sometimes useful for teaching purposes, so I'm -0 on optimizing this case.
I agree, and wished sequences used a __join__ method instead of __add__.
The '&' is already used for Bitwise And. How about '++' instead?
'hello ' ++ 'world' == "hello world"
[1, 3, 3] ++ [4, 5, 6] == [1, 2, 3, 4, 5, 6]
While this doesn't seem like a big change, I think it would simplify code
in many places that is more complicated than it really needs to be.
Cheers,
Ron
More information about the Python-ideas
mailing list