sum(strings)

John Roth johnroth at ameritech.net
Thu Jun 19 13:07:21 EDT 2003


"Raymond Hettinger" <vze4rx4y at verizon.net> wrote in message
news:uZlIa.10$38.9 at nwrdny01.gnilink.net...
>
> "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.

I don't think it's a bad idea at all. For me, the killer
is the inability to find a good, non-error return for
an empty list.

John Roth
>
>
> Raymond Hettinger
>
>






More information about the Python-list mailing list