Author syeberman
Recipients abarry, barry, mrabarnett, rhettinger, serhiy.storchaka, syeberman
Date 2016-12-12.04:22:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1481516521.19.0.168126027781.issue28937@psf.upfronthosting.co.za>
In-reply-to
Content
In the sep!=None case, there are existing alternatives to prune=True that aren't many more keystrokes:

>>> ''.split(' ', prune=True)
[]
>>> [x for x in ''.split(' ') if x]
[]
>>> list(filter(bool, ''.split(' '))) # or drop list() and use the iterator directly
[]

This becomes even fewer keystrokes for users that create a prune() or split_prune() function.

For the sep==None case, I agree there are no alternatives to prune=False (aside from rolling your own split function).  However, instead of prune, what if sep accepted a tuple of strings, similar to startswith.  In this case, each string would be considered one possible, yet distinct, delimiter:

>> ''.split(prune=False)
['']
>> ''.split((' ', '\t')) # typical whitespace
['']
>> ''.split(tuple(string.whitespace)) # ASCII whitespace
['']

Once again, this becomes even easier for users that create a split_no_prune() function, or that assign tuple(string.whitespace) to a variable.  It would also nicely handle strings with non-homogeneous delimiters:

>>> '1?2,,3;'.split((',', ';', '?'))
['1', '2', '', '3', '']

I personally find the 0-argument str.split() one of the great joys of Python.  It's common to have to split out words from a sentence, and having that functionality just 8 characters away at all times has been very useful.
History
Date User Action Args
2016-12-12 04:22:01syebermansetrecipients: + syeberman, barry, rhettinger, mrabarnett, serhiy.storchaka, abarry
2016-12-12 04:22:01syebermansetmessageid: <1481516521.19.0.168126027781.issue28937@psf.upfronthosting.co.za>
2016-12-12 04:22:01syebermanlinkissue28937 messages
2016-12-12 04:22:00syebermancreate