Given a list, I want to group them into a nested list of size 5 in O(N) complexity WITHOUT SLICING.
Example an input of:
[5,2,4,7,6,3,4,8,9,3,2,1]
Output:
[[5,2,4,7,6], [3,4,8,9,3], [2,1]]
without importing any packages as well.
So far, I've correctly done
def grouper(lst, size):
groups = []
for i in range(len(lst)%size + 1):
groups.append([])
which returns [[],[],[]]
.
I've been trying to implement a while
loop but I just can't find a way to keep count of the index of groups and index of list at the same time.