I want to split a given python list into chunks, similar to the following link, but in reverse.
How do you split a list into evenly sized chunks in Python?
Currently forward_chunk([1,2,3],2) = [[1,2], [3]]
However I want 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]
I cannot for the life of me make all the ranges and list slices work in order to achieve the backward dream. Anyone have any ideas?