[Python-ideas] The non-obvious nature of str.join (was Re: sum(...) limitation)

Stephen Hansen me+python at ixokai.io
Mon Aug 11 19:52:31 CEST 2014


On Mon, Aug 11, 2014 at 10:14 AM, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:
>
>  it makes sense in your native language.
>

No, it makes no sense at all in my native language. sum is, fundamentally,
the total of numbers in my native language.


> When you are tasked with finding s1 + s2 + ... + sN given [s1, s2, ...,
> sN], it is sum that first comes to mind, not join.
>

It would have never occurred to me in a million years to address such a
problem with sum. The first thing that'd likely have come to my mind a
million years ago when I first started learning Python would be to look for
some concat function, but failing that I'd run across join in the docs.


>  The situation is different when you have a separator to begin with, but
> when you don't using an empty separator feels like a performance hack in
> the absence of an efficient natural solution.
>

I'm pretty much going to just bow out at this point because the idea that
"".join(list_of_strings) is some weird and non-obvious thing but when it
has a separator, its clear and obvious, doesn't make any sense at all to
me. That seems to fly directly in the face of "there should be one...."
which you previously quoted.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140811/028ea25a/attachment-0001.html>


More information about the Python-ideas mailing list