this might look like a simple question but I could not figure out the solution.
Assuming I have this list
my_list = [1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99]
I am attempting to slice item in this list and increment it by index. In short, I want to get the result like this
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
[4, 5, 6]
[5, 6, 7]
[6, 7, 8]
[7, 8, 9]
[8, 9, 11]
[9, 11, 22]
[11, 22, 33]
[22, 33, 44]
[33, 44, 55]
[44, 55, 66]
[55, 66, 77]
[66, 77, 88]
[77, 88, 99]
But what I got is like this
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
[4, 5, 6]
[5, 6, 7]
[6, 7, 8]
[7, 8, 9]
[8, 9, 11]
[9, 11, 22]
[11, 22, 33]
[22, 33, 44]
[33, 44, 55]
[44, 55, 66]
[55, 66, 77]
[66, 77, 88]
[77, 88, 99]
[88, 99]
[99]
I want to slice my_list to several smaller set each with length of 3. But the result I got also included the list that have length below than 3.
This is the python script I use
my_list = [1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99]
m = 0
def incr():
    global m
    for n in range(len(my_list)):
        if n < len(my_list):
            n = m + 3
            new_list = my_list[m:n]
            print new_list
            m+=1
        else:
            pass
incr()
I figured that I could add if len(new_list) < 3 but I do not quite sure how should I modify the script for that.
Thank you for your help.
 
     
     
    