I want to split a given python list into chunks, similar to the following link, but in reverse.
Currently I have the output forward_chunk([1,2,3],2) = [[1,2], [3]]
However I want the output backward_chunk([1,2,3],2) = [[1], [2,3]]
# what I currently have
def forward_chunk(list, size):
for i in range(0, len(list), size):
yield list[i:i+size]
Despite my best efforts, I am unable to get the ranges and list slices to work and achieve the desired result. Does anyone have any suggestions?