reduce to be removed?
fredrik at pythonware.com
Sun Nov 12 00:14:37 CET 2006
> It's always nice to know there are such good-natured people ready to
> help on this group.
any special reason why you keep pretending that some random wikipedia
editor knows more about a future Python release than the people that
develops Python ?
> 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]], )
sum() is designed for adding numbers, not sequences. abusing it
for sequences leads to inefficient code, and extremely bad worst-
case behaviour, since you end up copying the same data over and
over and over again -- the function even checks for strings for
this very reason:
>>> sum(["123", "456", "789"], "")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: sum() can't sum strings [use ''.join(seq) instead]
(maybe it should check for other well-known containers as well?)
if you care about writing robust code, why not just use a for-loop,
and the list extend method?
More information about the Python-list