restriction on sum: intentional bug?
Peter Otten
__peter__ at web.de
Fri Oct 16 12:16:41 EDT 2009
Alan G Isaac wrote:
> I expected this to be fixed in Python 3:
>
>>>> sum(['ab','cd'],'')
> 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,
>
>>>> '' + 'ab' + 'cd'
> 'abcd'
>
> Why doesn't duck typing apply to `sum`?
Our beloved language for "consenting adults" has its kindergarten moments...
Peter
More information about the Python-list
mailing list