[Python-ideas] Optional keepsep argument in str.split()
Bruce Leban
bruce at leapyear.org
Thu Aug 29 08:26:34 CEST 2013
On Wed, Aug 28, 2013 at 10:49 PM, Jared Grubb <jared.grubb at gmail.com> wrote:
> Split and join are inverses, so it's lossless.
>
That's not true. If a separator is specified, it's lossless, but not in
this case:
>>> 'a b c d'.split()
['a', 'b', 'c', 'd']
>>> ' '.join('a b c d'.split())
'a b c d'
I don't see a compelling use case for modifying split though. If I wanted
to keep separators around, I'd probably want to work with lists like these:
['a', ' ', 'b', ' ', 'c', ' ', 'd']
or
[['a', ' '], ['b', ' '], ['c', ' '], ['d', '']]
and changing split to return either of those would be a bad idea.
--- Bruce
I'm hiring: http://www.cadencemd.com/info/jobs
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130828/c52669d7/attachment.html>
More information about the Python-ideas
mailing list