In article <[email protected]>, Steven D'Aprano <[email protected]> wrote: > >Mathematically, sum() is defined as the repeated application of the + >operator. In Python, the + operator is well-defined for strings and lists >as well as numbers. Since you can say "ab" + "cd" + "ef" and get a >sensible result, then sum() should be able to do the same thing. > >And indeed, if you pass a list-of-lists to sum(), it does: > >>>> sum([[1,2], ['a',None], [1,'b']], []) >[1, 2, 'a', None, 1, 'b'] > >(For the record, summing lists is O(N**2), and unlike strings, there's no >optimization in CPython to avoid the slow behaviour.)
Are you sure? -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." [email protected] -- http://mail.python.org/mailman/listinfo/python-list
