restriction on sum: intentional bug?
Alan G Isaac
alan.isaac at gmail.com
Fri Oct 16 18:11:27 CEST 2009
> Alan G Isaac schrieb:
>> I expected this to be fixed in Python 3:
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in<module>
>> TypeError: sum() can't sum strings [use ''.join(seq) instead]
>> Of course it is not a good way to join strings,
>> but it should work, should it not? Naturally,
On 10/16/2009 11:58 AM, Christian Heimes wrote:
> It's not a bug. sum() doesn't work on strings deliberately. ''.join()
> *is* the right and good way to concatenate strings.
You're not responding the the question at all:
the subject says "intentional bug?" and
the msg already noted that `join` is preferred,
but the part of the msg you cut out
asks why a violation of duck typing
So of course join is better, as originally noted,
but that does not constitute a reason to intentionally
violate duck typing.
More information about the Python-list