def splitter(s, points):
    c = 0
for x, y in points:
    yield s[c:x]
yield '(%s)' % s[x:y + 1]
c = y + 1
yield s[c:]
print(list(splitter(str, split_points)))
print(list(x for x in splitter(str, split_points) if x != ''))
Given a list of slices, how do I split a sequence by them?