Вы можете использовать понимание списка с iter
и next
:
words = ['apple', 'orange', 'oof', 'banana', 'apple', 'cherries', 'tomato']
n = ['2', '1', '4']
new_words = iter(words)
result = [[next(new_words) for _ in range(int(i))] for i in n]
Выход:
[['apple', 'orange'], ['oof'], ['banana', 'apple', 'cherries', 'tomato']]