How python forms this format

[br > 0:4, 4:7, 5"]
there is a rule here. From row 1 to x, I want to make up
0:4, 4:7, 11:12
0:4, that is, four starting at zero. 4:7 is from 4 to the last 2 7:9 is from 7 to the last 3:
, and so on, to form a dictionary or list

Mar.15,2021

looks 0:4 , 4:7 ,. It can be regarded as the subscript of an array and can be reduced to 4 , 3 ,.

then the problem evolves into a sequence of the same number of elements to generate a corresponding array, as follows

def compute(*size_list):
    l2 = []
    for i, size in enumerate(size_list):
        l2.extend([str(i+1)] * size)
    return l2


def test_compute():
    assert compute(4, 3, 2, 2, 1) == [
        '1', '1', '1', '1',
        '2', '2', '2',
        '3', '3',
        '4', '4',
        '5',
    ]
Menu