This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author oggust
Recipients oggust
Date 2009-10-20.13:48:54
SpamBayes Score 2.5289973e-08
Marked as misclassified No
Message-id <1256046536.74.0.518761053354.issue7176@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-10-20 13:48:57oggustsetrecipients: + oggust
2009-10-20 13:48:56oggustsetmessageid: <1256046536.74.0.518761053354.issue7176@psf.upfronthosting.co.za>
2009-10-20 13:48:55oggustlinkissue7176 messages
2009-10-20 13:48:54oggustcreate