[issue28937] str.split(): allow removing empty strings (when sep is not None)
Mark Bell
report at bugs.python.org
Sat Jun 5 05:46:30 EDT 2021
Mark Bell <mark00bell at googlemail.com> added the comment:
Andrei: That is a very interesting observation, thank you for pointing it out. I guess your example / argument also currently applies to whitespace separation too. For example, if we have a whitespace separated string with contents:
col1 col2 col3
a b c
x y z
then using [row.split() for row in contents.splitlines()] results in
[['col1', 'col2', 'col3'], ['a', 'b', 'c'], [], ['x', 'y', 'z']]
However if later a user appends the row:
p q
aiming to have p, and empty cell and then q then they will actually get
[['col1', 'col2', 'col3'], ['a', 'b', 'c'], [], ['x', 'y', 'z'], ['p', 'q']]
So at least this patch results in behaviour that is consistent with how split currently works.
Are you suggesting that this is something that could be addressed by clearer documentation or using a different flag name?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue28937>
_______________________________________
More information about the Python-bugs-list
mailing list