flatten a level one list

Alex Martelli aleax at mail.comcast.net
Fri Jan 13 10:48:39 EST 2006


Nick Craig-Wood <nick at craig-wood.com> wrote:
   ...
> I agree with Guido about the special case, but I disagree about the
> error message.  Not being able to use sum(L,"") reduces the
> orthogonality of sum for no good reason I could see.

Having sum(L,'') work but be O(N squared) would be an "attractive
nuisance" within the meaning of the law; it's bad enough that sum(L,[])
etc are that way, but at least beginners want to concatenate lists (or
tuples, arrays, etc) much less often than they want to concatenate
strings.  sum is meant to work on _numbers_ -- the reason it takes that
second optional parameter is essentially to be able to specify the
``type'' of numbers.  In retrospect it might have been better to have a
single argument (or interpret multiple ones like min or max do, maybe),
forcing the starting value to be integer 0.


Alex



More information about the Python-list mailing list