def group(l,size):
length = len(l)
new = []
for i in range(0,length):
for j in range(i,size):
new[i].append(l[j])
print new
The above function group(list, size) that take a list and splits into smaller lists of given size.
I need something like this
input: group([1, 2, 3, 4, 5, 6, 7, 8, 9], 3)
output: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
But the problem with the above code is showing index out of range.what's wrong in code? how to append elements into list of lists?