def permute(x, p, last, ind, t):
s = len(x)
for i in range(s):
p[ind] = x[i]
if(ind == last):
print(p)
t.append(p)
else:
permute(x, p, last, ind+1, t)
x is the original list of elements say [1,2,3] p is the list for generating permutations. its [0,0,0] initially. t is an empty list for getting ( appending ) all the permutations.
print(p) statement prints the correct permutations but when I try to append p list to t list I am not getting the desired output.
The t list that I am getting is -
[3]
[2]
[3, 3]
[3, 3]
[3, 3]
[3, 3]
[1]
[3, 3]
[3, 3]
[3, 3]
[3, 3]
[2, 2]
[2, 2]
[2, 2]
[2, 2]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
[3, 3, 3]
Where I am making mistake ? Thanks in advance !