This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: list(str.split(ch)) Does not print blank elements upon repeating character(ch)
Type: enhancement Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AmanPriyanshu, ammar2
Priority: normal Keywords:

Created on 2019-09-21 22:19 by AmanPriyanshu, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16324 closed AmanPriyanshu, 2019-09-21 22:19
Messages (2)
msg352955 - (view) Author: Aman Priyanshu (AmanPriyanshu) * Date: 2019-09-21 22:19
I have been annoyed by the fact that at multiple where we print list(str.split(ch)) we get empty elements in place of repeated characters (ch).

Example:

####
>>> print(list("Hello World How Are You?".split(" ")))
['Hello', 'World', 'How', 'Are', 'You?']
>>> print(list("Hello World       How Are      You?".split(" ")))
['Hello', 'World', '', '', '', '', '', '', 'How', 'Are', '', '', '', '', '', 'You?']
####

So can it be fixed so that  it gives:

####
>>> print(list("Hello World How Are You?".split(" ")))
['Hello', 'World', 'How', 'Are', 'You?']
>>> print(list("Hello World       How Are      You?".split(" ")))
['Hello', 'World', 'How', 'Are', 'You?']
####
msg352956 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2019-09-21 23:19
For whitespace, the correct way to achieve this using split() with no argument:

>>> print(list("Hello World How Are You?".split()))
['Hello', 'World', 'How', 'Are', 'You?']
>>> print(list("Hello World       How Are      You?".split()))
['Hello', 'World', 'How', 'Are', 'You?']

Your proposed solution would be a breaking change to all code that relies on the old style.
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82428
2019-09-21 23:19:45ammar2setnosy: + ammar2
messages: + msg352956
2019-09-21 22:47:44AmanPriyanshusetstatus: open -> closed
stage: resolved
2019-09-21 22:19:50AmanPriyanshucreate