Nov-30-2018, 06:59 PM
Hello,
I am trying to get the following List output [[2,3,4,5],[3,4,5,6],[4,5,6,7],[5,6,7,8] with a nested For loop. I am able to get the outer list but not the individual lists within the list. Here's my code and the output. Can you please suggest what I need to change to get the desired output and thank you in advance for your help.
Kind regards,
I am trying to get the following List output [[2,3,4,5],[3,4,5,6],[4,5,6,7],[5,6,7,8] with a nested For loop. I am able to get the outer list but not the individual lists within the list. Here's my code and the output. Can you please suggest what I need to change to get the desired output and thank you in advance for your help.
Kind regards,
my_list = [2,3,4,5] lst = [] for i in my_list: for j in range(0,4): lst.append(i+j) print(lst)[2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8]