Given an input list
l = [1 2 3 4 5 6 7 8 9 10]
and group size grp and step step
grp = 3; step = 2
I would like return a list. Note the repetition at the end
1 2 3
3 4 5
5 6 7
7 8 9
9 10 1
or if
grp= 4; step = 2
The output should be
1 2 3 4
3 4 5 6
5 6 7 8
7 8 9 10
This is the code I came up with it does not do the cyclic thing. But would like to know if there is a smaller or a simpler solution
def grouplist(l,grp,step):
oplist = list()
for x in range(0,len(l)):
if (x+grp<len(l)):
oplist.append(str(l[x:x+grp]))
return oplist
step=2so the first number on the second row should be3which it is.