The following code:
str = 'Welcome
to
PythonExamples
Welcome
to
PythonExamples'
chunks = str.split('
')
print(chunks)
Correctly prints out:
['Welcome', 'to', 'PythonExamples', 'Welcome', 'to', 'PythonExamples']
I want to split the string into strings that start with 'Welcome ' so I have tried the following:
str = 'Welcome
to
PythonExamples
Welcome
to
PythonExamples'
chunks = str.split('Welcome
')
print(chunks)
But this prints out:
['', 'to
PythonExamples
', 'to
PythonExamples']
Notice how the first entry is empty. How can I split it up correctly so that the output is?
['to
PythonExamples
', 'to
PythonExamples']
question from:https://stackoverflow.com/questions/66068367/split-python-string-without-empty-strings