I'm trying to make a function which holds all combination elements of list. The detail is like this.
This is when list elements are [1,2,3] and n=4. example,
elements=[1,2,3]
all_data=[]
for x_1 in elements:
tmp=[]
tmp.append(x_1)
all_data.append(tmp)
for x_2 in elements:
tmp=[]
tmp.append(x_1)
tmp.append(x_2)
all_data.append(tmp)
for x_3 in elements:
tmp=[]
tmp.append(x_1)
tmp.append(x_2)
tmp.append(x_3)
all_data.append(tmp)
for x_4 in elements:
tmp=[]
tmp.append(x_1)
tmp.append(x_2)
tmp.append(x_3)
tmp.append(x_4)
all_data.append(tmp)
all_data
Output is →
[[1],
[1, 1],
[1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 2],
[1, 1, 1, 3],
[1, 1, 2],
[1, 1, 2, 1],
[1, 1, 2, 2],
[1, 1, 2, 3],
[1, 1, 3],
[1, 1, 3, 1],
[1, 1, 3, 2],
[1, 1, 3, 3],
[1, 2],
[1, 2, 1],
[1, 2, 1, 1],
[1, 2, 1, 2],
[1, 2, 1, 3],
[1, 2, 2],
[1, 2, 2, 1],
[1, 2, 2, 2],
[1, 2, 2, 3],
[1, 2, 3],
[1, 2, 3, 1],
[1, 2, 3, 2],
[1, 2, 3, 3],
[1, 3],
[1, 3, 1],
[1, 3, 1, 1],
[1, 3, 1, 2],
[1, 3, 1, 3],
[1, 3, 2],
[1, 3, 2, 1],
[1, 3, 2, 2],
[1, 3, 2, 3],
[1, 3, 3],
[1, 3, 3, 1],
[1, 3, 3, 2],
[1, 3, 3, 3],
[2],
[2, 1],
.....
[3, 2, 3],
[3, 2, 3, 1],
[3, 2, 3, 2],
[3, 2, 3, 3],
[3, 3],
[3, 3, 1],
[3, 3, 1, 1],
[3, 3, 1, 2],
[3, 3, 1, 3],
[3, 3, 2],
[3, 3, 2, 1],
[3, 3, 2, 2],
[3, 3, 2, 3],
[3, 3, 3],
[3, 3, 3, 1],
[3, 3, 3, 2],
[3, 3, 3, 3]]
But what I wanna achieve is to make a function of this doing for n times using (probably) loop statement. So, the function's output I wanna make should be going to be like,
[[1],
[1,1],
......
[1,1,1,1,......,1], #(1 of n times)
[1,1,1,1,......,2],
......
[6],
[6,6],
......
[6,6,6,6,......,6]] #(n times)
Though I've spent almost whole week to tackle this question, not yet reached to any solution. Could anyone give me some tips or happen to know any ideas? Any clue is very welcome.
Thank you.