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

2009-10-26 Thread Ezio Melotti
Changes by Ezio Melotti : -- nosy: +ezio.melotti ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pyt

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

2009-10-26 Thread Björn Augustsson
Björn Augustsson added the comment: On Tue, Oct 20, 2009 at 20:19, Raymond Hettinger wrote: > > Raymond Hettinger added the comment: > > One use of the start argument is used to specify an initial zero/metpy > value for the summation:  0  or  0.0   or Decimal(0)  or  []. That means it's basic

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

2009-10-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: One use of the start argument is used to specify an initial zero/metpy value for the summation: 0 or 0.0 or Decimal(0) or []. BTW, sum() isn't a good technique for concatenating lists. Instead use something like: result = [] for seq in data:

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

2009-10-20 Thread Björn Augustsson
Björn Augustsson added the comment: Er, that's fairly weird... Couldn't it do eg "type(first argument)", and if it's a list, replace the 0 with []? What's the second argument's use anyway? s = sum([1,2,3,4]) + 3 seems a lot clearer than s = sum([1,2,3,4], 3) and those seem to be equivalen

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

2009-10-20 Thread Mark Dickinson
Mark Dickinson added the comment: To sum lists, you need to supply a second argument to sum: >>> sum([[1, 2], ['x', 'y']], []) [1, 2, 'x', 'y'] The default value of the second argument is 0, which is why you're seeing the TypeError. -- nosy: +mark.dickinson resolution: -> invalid st

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

2009-10-20 Thread Björn Augustsson
New submission from Björn Augustsson : 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",