There is no multisplit in Python, so it's a good occasion to implement it yourself.
I know a functional way how I would go using numpy
and I'll try to repeat the same steps using Python purely:
from itertools import accumulate
s = '294216673539910447'
numbers = [3, 2, 3, 3, 2, 2, 3]
idx = list(accumulate(numbers, initial=0))
print([s[i:j] for i,j in zip(idx[:-1], idx[1:])])
This illustrates a beautiful way to apply cumulative sums. accumulate
calculates index positions and they are [0, 3, 5, 8, 11, 13, 15, 18]
. So you need to arrange them properly to get slices 0:3
, 3:5
, ..., 15:18
.
Output
['294', '21', '667', '353', '99', '10', '447']