sum(strings)
Raymond Hettinger
vze4rx4y at verizon.net
Thu Jun 19 12:59:06 EDT 2003
"Steve McAllister" <nosp at m.needed> wrote in message
news:bcsjii$3vf$1 at alto.univ-mlv.fr...
> Why does sum reject strings?
Because there is just one right way to do it:
"".join([str1, str2, str3, ...])
Summing involves use of the repeated adds which
is terribly inefficient for strings. But, if you must:
reduce(str.__add__, [str1, str2, str3, ...], '')
Besides, it's very nice to be able to specify the join
character or blank.
> Is it a matter of efficiency of the
> underlying implementation?
Nope, it's is just a bad idea.
Raymond Hettinger
More information about the Python-list
mailing list