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

2021-06-16 Thread Andrei Kulakov
Andrei Kulakov added the comment: Just to sum up the current state the way I see it, as well as the history of the discussion, I think there were 2 initial requests based on experience and one additional, more theoretical "nice to have": A. ''.split() => [''] B. ''.split(sep) => [] # where

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

2021-06-05 Thread Andrei Kulakov
Andrei Kulakov added the comment: > Of course, but the main thing is that you spotted this before the PR was > merged :) I know, better late then never but also better sooner than late :-) -- ___ Python tracker

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

2021-06-05 Thread Andrei Kulakov
Andrei Kulakov added the comment: > I imagine that the discussion focussed on this since this is precisely what > happens when sep=None. For example, 'a b c ​'.split() == ['a', 'b', > 'c']. I guess that the point was to provide users with explicit, manual > control over whether the

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

2021-06-05 Thread Mark Bell
Mark Bell added the comment: > Instead, the discussion was focused on removing *all* empty strings from the > result. I imagine that the discussion focussed on this since this is precisely what happens when sep=None. For example, 'a b c ​'.split() == ['a', 'b', 'c']. I guess that

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

2021-06-05 Thread Andrei Kulakov
Andrei Kulakov added the comment: To clarify with pseudocode, this is how it could work: '' => [] # sep=None, keep_single_empty=False '' => [''] # sep=None, keep_single_empty=True '' => [] # sep=',', keep_single_empty=False 'a,,' => ['a','','']# sep=',',

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

2021-06-05 Thread Andrei Kulakov
Andrei Kulakov added the comment: Mark: With sep=None, I don't think there is an issue. My only concern is when sep is set to some other value. The original issue was that the single empty str result is removed when using sep=None and that it's kept when sep is some other value. So the

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

2021-06-05 Thread Mark Bell
Mark Bell 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

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

2021-06-02 Thread Andrei Kulakov
Andrei Kulakov added the comment: I'm not sure I understand why the discussion was focused on removing *all* empty values. Consider this in a context of a cvs-like string: 1. 'a,b,c' => [a,b,c]# of course 2. ',,'=> ['','',''] # follows naturally from above 3. '' => [] #

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

2021-05-21 Thread Matthew Barnett
Matthew Barnett added the comment: I've only just realised that the test cases don't cover all eventualities: none of them test what happens with multiple spaces _between_ the letters, such as: ' a b c '.split(maxsplit=1) == ['a', 'b c '] Comparing that with: ' a b c '.split('

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

2021-05-20 Thread Mark Bell
Mark Bell added the comment: Thank you very much for confirming these test cases. Using these I believe that I have now been able to complete a patch that would implement this feature. The PR is available at https://github.com/python/cpython/pull/26222. As I am a first-time contributor,

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

2021-05-18 Thread Mark Bell
Change by Mark Bell : -- pull_requests: +24839 pull_request: https://github.com/python/cpython/pull/26222 ___ Python tracker ___

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

2021-05-18 Thread Matthew Barnett
Matthew Barnett added the comment: We have that already, although it's spelled: ' x y z'.split(maxsplit=1) == ['x', 'y z'] because the keepempty option doesn't exist yet. -- ___ Python tracker

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

2021-05-18 Thread Mark Bell
Mark Bell added the comment: So I think I agree with you about the difference between .split() and .split(' '). However wouldn't that mean that ' x y z'.split(maxsplit=1, keepempty=False) == ['x', 'y z'] since it should do one split. -- ___

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

2021-05-18 Thread Matthew Barnett
Matthew Barnett 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)

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

2021-05-18 Thread Mark Bell
Mark Bell added the comment: > suggests that empty strings don't count towards maxsplit Thank you for the confirmation. Although just to clarify I guess you really mean "empty strings *that are dropped from the output* don't count towards maxsplit". Just to double check this, what do we

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

2021-05-18 Thread Matthew Barnett
Matthew Barnett added the comment: The case: ' a b c '.split(maxsplit=1) == ['a', 'b c '] suggests that empty strings don't count towards maxsplit, otherwise it would return [' a b c '] (i.e. the split would give ['', ' a b c '] and dropping the empty strings would give [' a b c

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

2021-05-18 Thread Mark Bell
Mark Bell added the comment: So I have taken a look at the original patch that was provided and I have been able to update it so that it is compatible with the current release. I have also flipped the logic in the wrapping functions so that they take a `keepempty` flag (which is the opposite

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

2021-05-17 Thread Catherine Devlin
Catherine Devlin added the comment: @ZackerySpytz - I made https://github.com/python/cpython/pull/26196 with a test for the desired behavior; hopefully it helps. I could try to adapt Barry's old patch myself, but it's probably better if somebody C-competent does so... --

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

2021-05-17 Thread Catherine Devlin
Change by Catherine Devlin : -- nosy: +Catherine.Devlin nosy_count: 11.0 -> 12.0 pull_requests: +24813 stage: test needed -> patch review pull_request: https://github.com/python/cpython/pull/26196 ___ Python tracker

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

2021-01-12 Thread Dong-hee Na
Change by Dong-hee Na : -- nosy: +corona10 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

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

2021-01-04 Thread Guido van Rossum
Guido van Rossum added the comment: Excellent! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

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

2021-01-04 Thread Zackery Spytz
Zackery Spytz added the comment: I am working on this issue. -- assignee: -> ZackerySpytz nosy: +ZackerySpytz versions: +Python 3.10 -Python 3.8 ___ Python tracker ___

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

2021-01-03 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: -rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

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

2021-01-03 Thread Guido van Rossum
Guido van Rossum added the comment: This issue probably needs a new champion. There is broad agreement but some bike shedding, so a PEP isn’t needed.-- --Guido (mobile) -- ___ Python tracker

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

2021-01-03 Thread karl
Change by karl : -- nosy: +karlcow ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

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

2019-10-18 Thread Philippe Cloutier
Philippe Cloutier added the comment: I assume the "workaround" suggested by Raymond in msg282966 is supposed to read... filter(None, str.split(sep) ... rather than filter(None, sep.split(input)). -- ___ Python tracker

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

2019-10-18 Thread Philippe Cloutier
Philippe Cloutier added the comment: I understood the current (only) behavior, but coming from a PHP background, I really didn't expect it. Thank you for this request, I would definitely like the ability to get behavior matching PHP's explode(). -- nosy: +Philippe Cloutier title: