[Python-ideas] [...].join(sep)

Boris Borcic bborcic at gmail.com
Wed May 23 16:50:18 CEST 2012


Terry Reedy wrote:
> On 5/21/2012 10:27 AM, Boris Borcic wrote:
>> anatoly techtonik wrote:
>>> I am certain this was proposed many times, but still - why it is
>>> rejected?
>>>
>>> "real man don't use spaces".split().join('+').upper()
>>> instead of
>>> '+'.join("real man don't use spaces".split()).upper()
>>
>> IMO this should really be :
>>
>> '+'.join(' '.split("real man don't use spaces")).upper()
>
> It the separator were a mandatory argument for .split, then that would be
> possible, not not with it being optional, and therefore the second argument.
>
>  >>> ' real men usE SPAces and tabs'.split()
> ['real', 'men', 'usE', 'SPAces', 'and', 'tabs']
>  >>> ' real men usE SPAces and tabs'.split(' ')
> ['', 'real', '', 'men', '', 'usE', 'SPAces', '', '', 'and', '\t', 'tabs']
>
>  >>> ' '.join(' real men usE SPAces and tabs'.split())
> 'real men usE SPAces and tabs'
>
> is a handy way to clean up whitespace
>

Kind of beside the point, which is that the desire to repair the inconsistency 
between split and join has a better prospect at the split side of things than at 
the join side of things. The problems at the split side of things are 
comparatively minor.




More information about the Python-ideas mailing list