reduce to be removed?
Steve Holden
steve at holdenweb.com
Mon Nov 13 04:42:53 EST 2006
Paddy wrote:
> Dustan wrote:
>
>> Anyway, I figured out a way to get the builtin
>> function 'sum' to work as I need:
>> sum([[1,2,3],[4,5,6],[7,8,9]], [])
>>
>
> Hah!
> No-one expects sum to be used on anything but numbers.
>
> Except lists as above.
>
> No-one expects sum to be used on anything but numbers, and maybe lists
> too.
>
> ;-)
[voice mumbles:] "What about tuples"
Right, tuples too. But apart from tuples and lists, nobody expects sum
to be used on anything but numbers.
In actual fact when Alex Martelli introduced sum() he intended it to be
polymorphic over all the container types including strings. The check to
exclude the string case was added when it was determined that it was
terribly inefficient to concatenate strings that way. the same may well
apply to other sequences.
I suppose it's only a matter of time before someone wants to define
dict.__add__ ...
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list