Final result should look like this:
string = "this is a simple text"
result = ["this", " ", "is", " ", "a", " ", "simple", " ", "text"]
Final result should look like this:
string = "this is a simple text"
result = ["this", " ", "is", " ", "a", " ", "simple", " ", "text"]
One way to do this would be to split with a regex and capture the delimiter:
import re
string = "this is a simple text"
re.split(r'(\s+)', string)
# ['this', ' ', 'is', ' ', 'a', ' ', 'simple', ' ', 'text']
Note, this will act a little different than str.split()
on an empty string.