split string by arbitrary number of white spaces
How about:
re.split(r'\s+',string)
\s
is short for any whitespace. So \s+
is a contiguous whitespace.
Just use my_str.split()
without ' '
.
More, you can also indicate how many splits to perform by specifying the second parameter:
>>> ' 1 2 3 4 '.split(None, 2)
['1', '2', '3 4 ']
>>> ' 1 2 3 4 '.split(None, 1)
['1', '2 3 4 ']