I want to split a string by a list of indices, where the split segments begin with one index and end before the next one.
Example:
s = 'long string that I want to split up'
indices = [0,5,12,17]
parts = [s[index:] for index in indices]
for part in parts:
print part
This will return:
long string that I want to split up
string that I want to split up
that I want to split up
I want to split up
I'm trying to get:
long
string
that
I want to split up
[s[i:j] for i,j in izip_longest(indices,indices[1:])]
but I like your way better! – Anticathode