How to collapse consecutive delimiters?
You can use re.split
with a regular expression as the delimiter, as in:
re.split(pattern, string[, maxsplit=0, flags=0])
You could use regular expressions:
re.split(pattern, string[, maxsplit=0, flags=0])
as
re.split('a+', 'aaa')
This is about as concise as you can get:
string = 'aaa'
result = [s for s in string.split('a') if s]
Or you could switch to regular expressions:
string = 'aaa'
result = re.split('a+', string)