I'm trying to create a function that splits a list into n-sized chunks.
For example a function like this: fun([1,2,3,4], 3)
should output [[1,2,3],[2,3,4]]
.
I'm not sure if this is exactly what you want or not, but I would recommend:
def split_list(list, n):
toReturn = []
for i in range(len(list)//n):
toReturn.append(list[i*n:i*n+n])
toReturn.append(list[-n:])
return toReturn