[New-bugs-announce] [issue7176] sum() doesn't work for lists.

Björn Augustsson report at bugs.python.org
Tue Oct 20 15:48:56 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 

The docs say:

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

That's not true.
import operator


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.)


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>

More information about the New-bugs-announce mailing list