I have this list:
List = [1, 2, 3]
...and I want to print out all possible combinations such that the output is like:
[1]
[1,2]
[1, 2, 3]
[2]
[2, 3]
[3]
So far my code is this:
E=[]
i=0
for seq in L[i:]:
E.append(seq)
i += 1
print(E)
Which gives my first 3 outputs. Is there a way for me to loop it so that the index goes up by 1 so I can get my desired output?
Edit; so I basically want to write a code which summarizes this:
List = [1, 2, 3]
E = []
F = []
G = []
for seq in List[0:]:
E.append(seq)
print(E)
for seq in List[1:]:
F.append(seq)
print(F)
for seq in List[2:]:
G.append(seq)
print(G)
I pretty much want to know if I can loop the index so that I don't have to create multiple for loops and maybe apply it to a longer list.