[Python-ideas] Add list.join() please

Robert Vanden Eynde robertve92 at gmail.com
Wed Jan 30 01:02:35 EST 2019


>
> def stringify(self, sep):
>      return sep.join(str(i) for i in self)
>
= map(sep.join(map(str, self))

However some folks want:

def stringify(*args, *, sep:str=SomeDefault):
    return sep.join(map(str, args))

In order to have:

>>> stringify(1, 2, "3", sep="-")
1-2-3

And I agree about the formatting, we know that str(x) and format(x) are
synonyms so I'd suggest:

def stringify(*args, *, sep:str=SomeDefault, fmt=''):
    return sep.join(format(x, fmt) for x in args)

And the implicit call to str is really not surprising for a function called
stringify IMO

If you want a language designed specifically for text processing, use Perl.
>
True ! However typing python -cp "1+1" is really tempting...

>
Python is deliberately strongly typed, so that:
>
> 2 + “2”
>
> Raises an error. Why should:
>
> “”.join([2, “2”]) not raise an error as well?
>
I agree
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190130/f18f005b/attachment.html>


More information about the Python-ideas mailing list