The result list contains single spaces when splitting a string with re.split(“( )+”) – is there a better way?
By using (,), you are capturing the group, if you simply remove them you will not have this problem. >>> str1 = “a b c d” >>> re.split(” +”, str1) [‘a’, ‘b’, ‘c’, ‘d’] However there is no need for regex, str.split without any delimiter specified will split this by whitespace for you. This would … Read more