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

Terry Reedy tjreedy at udel.edu
Mon May 21 20:29:34 CEST 2012


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

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list