I have a list which is [1 x 29,584] in size, made up of the product of 172 input groups to 172 output groups. I need to split this list into 172 smaller lists of size [1 x 172]. The ordering is such that for the first smaller list, I need the 1st value, then the 173rd value, then the 345th value etc.
So far I have a preliminary function which does give me the desired list for the first set of values. However, it doesn't work for any subsequent values. I am also trying to keep all my functions in a separate file from the main code, and I am not sure how to call this function to ensure all the different groups get indexed correctly?
large_array_size = 172*172
small_array_size = 172
for i in [0,small_array_size]:
group_i = functions.collapse_list(results,large_array_size)
In functions file:
def collapse_list(results,large_array_size):
for i in [0,large_array_size]:
new_list_i = []
new_list_i = results[::(172+i)]
return(new_list_i)
I need to end up with lists group_1, group_2,..., group_172, each of which is made up of 172 values. Any help would be much appreciated.
question from:
https://stackoverflow.com/questions/66047944/collapse-large-list-into-smaller-lists-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…