[Python-ideas] Add list.join() please
Robert Vanden Eynde
robertve92 at gmail.com
Tue Jan 29 10:24:31 EST 2019
Oh and if you want to write ['a', 'b', 'c'].join('.')
Check out pip install funcoperators and you can write :
['a', 'b', 'c'] |join('.')
Given you defined the function below :
from funcoperators import postfix
def join(sep):
return postfix(lambda it: sep.join(map(str, it))
You can even choose the operator :
['a', 'b', 'c'] -join('.')
['a', 'b', 'c'] /join('.')
['a', 'b', 'c'] @join('.')
...
Disclaimer : I'm the creator of funcoperators
On Tue, 29 Jan 2019, 02:43 Jamesie Pic <jpic at yourlabs.org wrote:
> Hello,
>
> During the last 10 years, Python has made steady progress in convenience
> to assemble strings. However, it seems to me that joining is still, when
> possible, the cleanest way to code string assembly.
>
> However, I'm still sometimes confused between the different syntaxes used
> by join methods:
>
> 0. os.path.join takes *args
> 1. str.join takes a list argument, this inconsistence make it easy to
> mistake with the os.path.join signature
>
> Also, I still think that:
>
> '_'.join(['cancel', name])
>
> Would be more readable as such:
>
> ['cancel', name].join('_')
>
> Not only this would fix both of my issues with the current status-quo, but
> this would also be completely backward compatible, and probably not very
> hard to implement: just add a join method to list.
>
> Thanks in advance for your reply
>
> Have a great day
>
> --
> ∞
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190129/e200131d/attachment.html>
More information about the Python-ideas
mailing list