[Python-ideas] Add list.join() please
Robert Vanden Eynde
robertve92 at gmail.com
Tue Jan 29 04:13:10 EST 2019
>
>
> Personally what I find is perverse is that .join is a method of
> strings
> but does NOT call str() on the items to be joined.
Yeah, that's a good reason to use .format when you have a fixed number of
arguments.
"{}, {}, {}, {}".format(some, random, stuff, here)
And then there is map.
Otherwise .join is very common on iterables like
'\n'.join(make_string(object) for object in something)
'\n'.join(map(make_string, something))
'\n'.join(map(str, nonstr))
'\n'.join('{}: {}'.format(x, y) for x,y in blabla)
'\n'.join(map('[{}]'.format, stuff))
A "join format" construct is very typical in codes producing strings from
iterable.
I agree on the part "a list doesn't always contain string so why would it
have a join method".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190129/6f1c3465/attachment.html>
More information about the Python-ideas
mailing list