sum(strings)
Alex Martelli
aleax at aleax.it
Thu Jun 19 12:54:12 EDT 2003
Steve McAllister wrote:
>> Python is not Perl! If you need to build the sum over a sequence of
>> strings containing numbers
>> then you need to convert them to numbers.
>
> I am talking about sum(['x', 'y']) -> 'xy'.
> Since strings can be added, they should be sumable too. No? :-)
Nope. I thought so too, originally, and went out of my way in order
to let sum accept a sequence of strings (and deal with them rapidly,
just like ''.join does, of course) in the very first prototype of
sum. This caused a real mess when conjoined with such issues as
summing empty sequences and summing non-restartable iterators. The
knot was elegantly cut by Guido, who Pronounced that sum wanted to
be only and specifically about numbers -- and I think that, as is
the case more often than not, he was right.
Alex
More information about the Python-list
mailing list