Ad
Algorithms
Logic
Lists
Data Structures

Given an input list. Example [1,2,3,4,5,6] split it into a new list, where the items contained are split into longer and longer length lists in the parent list. Like: [[1], [2, 3], [4, 5, 6]].

If the list does not fill the chunk completly, fill it up party. [1,2,3,4] => [[1], [2, 3], [4]]

More examples:

[1, 2, 3, 4, 5, 6] => [[1], [2, 3], [4, 5, 6]]

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] => [[1], [2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14, 15], [16]]

def variable_chunks(lst):
    if lst == []:
        return [[]]
    result = []
    y = 0
    for x in range(1, len(lst) + 1):
        result.append(lst[y:y+x])
        y = y+x
    return [x for x in result if x != []]