s = 'ABCDE'
c = [[5], [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)
Python: I have a string and a list of lists of varying lengths and I want to return the letters in groups as they correspond to the list