[issue28937] str.split(): allow removing empty strings (when sep is not None)

Matthew Barnett report at bugs.python.org
Tue May 18 13:38:20 EDT 2021


Matthew Barnett <python at mrabarnett.plus.com> added the comment:

The best way to think of it is that .split() is like .split(' '), except that it's splitting on any whitespace character instead of just ' ', and keepempty is defaulting to False instead of True.

Therefore:

    '   x y z'.split(maxsplit=1, keepempty=True) == ['', '  x y z']

because:

    '   x y z'.split(' ', maxsplit=1) == ['', '  x y z']

but:

    '   x y z'.split(maxsplit=1, keepempty=False) == ['x y z']

At least, I think that's the case!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue28937>
_______________________________________


More information about the Python-bugs-list mailing list