<div dir="ltr"><div dir="ltr"><div dir="ltr">One could always write<div><br></div><div><font face="monospace, monospace">str.join('_', ['list', 'of', 'strings'])</font><br></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">I'm not advocating for this syntax, but perhaps it is clarifying. Also, a quick search finds this thread from 20 years ago on this very issue:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><a href="https://mail.python.org/pipermail/python-dev/1999-June/095366.html" target="_blank">https://mail.python.org/pipermail/python-dev/1999-June/095366.html</a><br></font></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail-m_2888125511667014615gmail_attr">On Mon, Jan 28, 2019 at 9:37 PM Ronie Martinez <<a href="mailto:ronmarti18@gmail.com" target="_blank">ronmarti18@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>If there is a more Pythonic way of joining lists, tuples, sets, etc., it is by using a keyword and not a method. For example, using a keyword, say <b>joins</b>:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>'-' joins ['list', 'of', 'strings']<br></div></blockquote><div><br></div><div>This is more readable than using the method join() since you can read this as "dash joins a list of strings". Although, the current method of joining lists is almost similar to this, the current method is somewhat "confusing" for beginners or for people who came from other languages.<br></div><div><br></div><div>BTW, this is just what comes in my mind and not supported by Python.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail-m_2888125511667014615gmail-m_-7710764146127583121gmail_attr">On Tue, Jan 29, 2019 at 1:22 PM Brendan Barnwell <<a href="mailto:brenbarn@brenbarn.net" target="_blank">brenbarn@brenbarn.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2019-01-28 18:22, David Mertz wrote:<br>
> On Mon, Jan 28, 2019 at 8:44 PM Jamesie Pic <<a href="mailto:jpic@yourlabs.org" target="_blank">jpic@yourlabs.org</a><br>
> <mailto:<a href="mailto:jpic@yourlabs.org" target="_blank">jpic@yourlabs.org</a>>> wrote:<br>
><br>
>     ['cancel', name].join('_')<br>
><br>
><br>
> This is a frequent suggestion.  It is also one that makes no sense<br>
> whatsoever if you think about Python's semantics.  What would you expect<br>
> to happen with this line:<br>
><br>
> ['foo', b'foo', 37, re.compile('foo')].join('_')<br>
><br>
>   List are not restricted to containing only strings (or things that are<br>
> string-like enough that they might play well with joining).  Growing a<br>
> method that pertains only to that specialized sort of list breaks the<br>
> mental model of Python.  Moreover, there is no way to TELL if a<br>
> particular list is a "list of strings" other than checking each item<br>
> inside it (unlike in many languages).<br>
<br>
        That problem already exists with str.join though.  It's just currently <br>
spelled this way:<br>
<br>
','.join(['foo', b'foo', 37, re.compile('foo')])<br>
<br>
        . . . and the result is an error.  I don't see how it's semantically <br>
any less sensible to call list.join on a list of non-string things than <br>
it is to pass a list of non-string things to str.join.<br>
<br>
        Personally what I find is perverse is that .join is a method of strings <br>
but does NOT call str() on the items to be joined.  The cases where I <br>
would have been surprised or bitten by something accidentally being <br>
converted to a string are massively outweighed by the cases where I want <br>
everything to be converted into a string, because, dangit, I'm joining <br>
them into a bigger string.<br>
<br>
        I agree that a list method would be nice, but we then have to think <br>
about should we add similar methods to all iterable types, since <br>
str.join can take any iterable (not just a list).<br>
<br>
-- <br>
Brendan Barnwell<br>
"Do not follow where the path may lead.  Go, instead, where there is no <br>
path, and leave a trail."<br>
    --author unknown<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>