list within a list
- by atm atm
I'm working on this problem, but I cannot figure out the second part. I tried using reverse list but it did not work out how I planned it.
Given a list L (e.g. [1,2,3,4]), write a program that generates the following nested lists:
L1 = [[1],[1,2],[1,2,3],[1,2,3,4]],
L2 = [[4],[3,4],[2,3,4],[1,2,3,4]].
My code that I have so far:
mylist=[,1,2,3,4]
print("Orginal list L=",mylist)
n=len(mylist)
l1=[]
l2=[]
for x in range(1,n+1,1):
l1.append(mylist[0:x])
print("L1=",l1) #prints final product of l1
mylist.reverse() #this is where i get messed up
for x in range(1,n+1,1):
l2.append(mylist[0:x])
print("L2=",l2)