I have a list that looks like this:
arr = [['3'], ['1', '0.0'], ['2', '0.05'], ['3', '0.1'], ['1', '1'], ['2', '1'], ['3', '1']]
I would like to break this list up into smaller sublists that are of the size given in the first element of the original list (e.g. 3 here) and only consist of the second element. What is the most pythonic way of doing this?
sublist1 = [0.0, 0.05, 0.1]
sublist2 = [1, 1, 1]
I've tried to use list comprehension, but I don't know how to prescribe the for
loop to loop through the array (i.e. between indices 1 and 3 or between indices 4 and 6 in the example arr
above).
n_nodes = arr[0][0] # gets number of nodes, 3
first_section = [element[1] for element in arr]