For example, if the following character string is divided by half-width spaces, an empty character string will be included in the element if there are multiple half-width spaces in the middle.
test1.py
time = "Dec 3 14:25:33"
words = time.split(" ")
print words #['Dec', '', '3', '14:25:33']
Solved by using a regular expression module.
test2.py
import re
time = "Dec 3 14:25:33"
words = re.split(" +", time)
print words #['Dec', '3', '14:25:33']
As you pointed out in the comment, if you omit the split argument, it seems that you can split with delimiters such as spaces, tabs, and line breaks without entering an empty string.
[Python practice book](http://php6.jp/python/basics/%E3%82%B9%E3%82%B3%E3%83%BC%E3%83%97/%E3%83%A2 % E3% 82% B8% E3% 83% A5% E3% 83% BC% E3% 83% AB /)
Recommended Posts