[issue7176] sum() doesn't work for lists.

Björn Augustsson report at bugs.python.org
Tue Oct 20 15:48:57 CEST 2009


New submission from Björn Augustsson <oggust at gmail.com>:

Summary: "sum()" doesn't work on lists, even though the docs says it 
should.

The docs say:

"Note that sum(range(n), m) is equivalent to reduce(operator.add, 
range(n), m)"

That's not true.
--------------------------------
import operator

a=[1,2]
b=["x","y"]

reduce(operator.add, [a,b])
# Works, gives "[1, 2, 'x', 'y']" as expected.

sum ([a,b])
# Does not work, gives: "TypeError: unsupported operand type(s) for +: 
'int' and 'list'"
--------------------------------
(And "a + b" obviously works too.)

/August.

----------
components: None
messages: 94275
nosy: oggust
severity: normal
status: open
title: sum() doesn't work for lists.
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7176>
_______________________________________


More information about the Python-bugs-list mailing list