Imagine that I have a string that is 5 letters long, say 'ABCDE'. I also have a list of lists of the different way to split the list i.e. [, [4, 1], [3, 2], ... [1, 1, 1, 1, 1]]. How could return all the different ways to split the list, like below. The problem I am having is setting up a loop with uneven numbers of indices.
['A', 'B', 'C', 'D', 'E']
If you want to apply that configuration list of lists containing possible "slices" of a string, here is a way to do it - basically, we take a slice and pass the rest of the string to the next step:
s = 'ABCDE' c = [, [4, 1], [3, 2], [1, 1, 1, 1, 1]] for item in c: result =  s_copy = s for index in item: result.append(s_copy[:index]) s_copy = s_copy[index:] print(result)
['ABCDE'] ['ABCD', 'E'] ['ABC', 'DE'] ['A', 'B', 'C', 'D', 'E']