Re: sum works in sequences (Python 3)

2012-09-19 Thread Hans Mulder
On 19/09/12 17:07:04, Alister wrote: > On Wed, 19 Sep 2012 16:41:20 +0200, Franck Ditter wrote: > >> Hello, >> I wonder why sum does not work on the string sequence in Python 3 : >> > sum((8,5,9,3)) >> 25 > sum([5,8,3,9,2]) >> 27 > sum('rtarze') >> TypeError: unsupported operand type(s

Re: sum works in sequences (Python 3)

2012-09-19 Thread Terry Reedy
On 9/19/2012 11:07 AM, Alister wrote: Summation is a mathematical function that works on numbers Concatenation is the process of appending 1 string to another although they are not related to each other they do share the same operator(+) which is the cause of confusion. If one represents coun

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steve Howell
On Sep 19, 11:34 am, Ian Kelly wrote: > On Wed, Sep 19, 2012 at 9:37 AM, Steve Howell wrote: > > Sequences are iterables, so I'd say the docs are technically correct, > > but maybe I'm misunderstanding what you would be trying to clarify. > > The doc string suggests that the argument to sum() mus

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 9:37 AM, Steve Howell wrote: > Sequences are iterables, so I'd say the docs are technically correct, > but maybe I'm misunderstanding what you would be trying to clarify. The doc string suggests that the argument to sum() must be a sequence, when in fact any iterable will

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steven D'Aprano
On Wed, 19 Sep 2012 15:07:04 +, Alister wrote: > Summation is a mathematical function that works on numbers Concatenation > is the process of appending 1 string to another > > although they are not related to each other they do share the same > operator(+) which is the cause of confusion. att

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steven D'Aprano
On Wed, 19 Sep 2012 09:03:03 -0600, Ian Kelly wrote: > I think this restriction is mainly for efficiency. sum(['a', 'b', 'c', > 'd', 'e']) would be the equivalent of 'a' + 'b' + 'c' + 'd' + 'e', which > is an inefficient way to add together strings. It might not be obvious to some people why rep

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steve Howell
On Sep 19, 8:06 am, Neil Cerutti wrote: > On 2012-09-19, Ian Kelly wrote: > > > It notes in the doc string that it does not work on strings: > > > sum(...) > >     sum(sequence[, start]) -> value > > >     Returns the sum of a sequence of numbers (NOT strings) plus > >     the value of parameter

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 9:06 AM, Neil Cerutti wrote: > Are iterables and sequences different enough to warrant posting a > bug report? The glossary is specific about the definitions of both, so I would say yes. http://docs.python.org/dev/glossary.html#term-iterable http://docs.python.org/dev/glo

Re: sum works in sequences (Python 3)

2012-09-19 Thread Neil Cerutti
On 2012-09-19, Ian Kelly wrote: > It notes in the doc string that it does not work on strings: > > sum(...) > sum(sequence[, start]) -> value > > Returns the sum of a sequence of numbers (NOT strings) plus > the value of parameter 'start' (which defaults to 0). When > the sequence

Re: sum works in sequences (Python 3)

2012-09-19 Thread Alister
On Wed, 19 Sep 2012 16:41:20 +0200, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > sum((8,5,9,3)) > 25 sum([5,8,3,9,2]) > 27 sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought t

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 8:41 AM, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > sum((8,5,9,3)) > 25 sum([5,8,3,9,2]) > 27 sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that s

Re: sum works in sequences (Python 3)

2012-09-19 Thread Neil Cerutti
On 2012-09-19, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > sum((8,5,9,3)) > 25 sum([5,8,3,9,2]) > 27 sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that sum('abc') would ex

Re: sum works in sequences (Python 3)

2012-09-19 Thread Joel Goldstick
On Wed, Sep 19, 2012 at 10:41 AM, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > sum((8,5,9,3)) > 25 sum([5,8,3,9,2]) > 27 sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that

sum works in sequences (Python 3)

2012-09-19 Thread Franck Ditter
Hello, I wonder why sum does not work on the string sequence in Python 3 : >>> sum((8,5,9,3)) 25 >>> sum([5,8,3,9,2]) 27 >>> sum('rtarze') TypeError: unsupported operand type(s) for +: 'int' and 'str' I naively thought that sum('abc') would expand to 'a'+'b'+'c' And the error message is somewhat