I want to split each list of lists into sublists of given length. I have a courses array which looks like this:
[['CS105', 'ENG101', 'MATH101', 'GER', 'ENG102', 'CS230', 'MATH120', 'GER', 'CS205', 'FREE', 'GER', 'CS106', 'CS215', 'CS107', 'ENG204', 'GER', 'MATH220', 'CS300', 'CS206', 'CS306', 'GER', 'FREE', 'CS312', 'CS450', 'GER', 'CS321', 'FREE', 'CS325', 'GER', 'CS322', 'MAJOR', 'CS310', 'STAT205', '', 'CS443', 'CS412', 'CS421', 'GER', 'CS444', 'FREE', 'FREE','','',''], ['CS105', 'ENG101', 'MATH101', 'GER', 'ENG102', 'CS230', 'MATH120', 'GER', 'CS205', 'FREE', 'GER', 'CS106', 'CS215', 'CS107', 'ENG204', 'GER', 'MATH220', 'CS300', 'CS206', 'CS306', 'GER', 'FREE', 'CS312', 'CS450', 'GER', 'CS321', 'FREE', 'CS325', 'GER', 'CS322', 'MAJOR', 'CS310', 'STAT205', '', 'CS443', 'CS412', 'CS421', 'GER', 'CS444', 'FREE', 'FREE','','',''],...]
I want to split each list in sublists in and them to look like this:
[[['CS105', 'ENG101', 'MATH101', 'GER'],['ENG102', 'CS230', 'MATH120', 'GER'], ['CS205', 'FREE'], ['GER'], ['CS106', 'CS215', 'CS107','ENG204', 'GER'], ['MATH220', 'CS300', 'CS206', 'CS306'], ['GER', 'FREE'], ['CS312'], ['CS450', 'GER', 'CS321', 'FREE', 'CS325'], ['GER', 'CS322', 'MAJOR', 'CS310'], ['STAT205',''], [''], ['CS443', 'CS412', 'CS421', 'GER',''], ['CS444', 'FREE', 'FREE',''],['','']]...]
what I have done till now is the following:
schedule = [4, 4, 2, 1, 5, 4, 2, 1, 5, 4, 2, 1, 5, 4, 2, 1]
for i in courses:
Output = [courses[x - y: x] for x, y in zip(accumulate(schedule), schedule)]
print(Output[0])
but what is printed with Output[0] is 4 lists in a row, so as I get it it takes pairs of 4 probably. schedule is the given lengths that I want each list to be splitted. I cannot understand how I need to loop probably in order to achieve the result I need.