[Python-ideas] Fast sum() for non-numbers
Terry Reedy
tjreedy at udel.edu
Fri Jul 5 22:25:46 CEST 2013
On 7/5/2013 12:22 PM, Ron Adam wrote:
>
>
> 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.
Agree here.
>> Traditionally, sum() works only on numbers, and I think we wouldn't be
>> having this discussion if Python used & for concatenation instead of
>> +.
Since addition of numbers represented in base-1 or tally notation is the
same as sequence concatenation, I think '+' is the right choice.
In my experience of American English, normal people 'add' lists (though
perhaps as sets, with duplicate removal), not 'concatenate' them. And
while they may 'add' together multiple lists, they would not likely
'sum' them unless they are lists of numbers.
When Alex said that it was not possible to determine if the start value
is a number, he was talking in the context of old style classes where
the type of every user class was 'Class' and the type of every user
instance was 'Instance' (or something like that). In Python 3, with
ABCs, isinstance(start, Number) would solve the problem as long as the
requirement were documented.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list