Here I wrote a recursive function to find the permutation of a list.
def backtrack(arr,tmp):
if len(tmp)==len(arr):
res.append(tmp)
#==print res here==
print(res)
else:
for i in range(len(arr)):
if arr[i] in tmp: continue
tmp.append(arr[i])
backtrack(arr,tmp)
tmp.pop()
if __name__ == '__main__':
points=[1,2,3]
res=[]
tmp=[]
backtrack(points,tmp)
print(res)
#code result
#[[1, 3, 2], [1, 3, 2]]
#[[2, 1, 3], [2, 1, 3], [2, 1, 3]]
#[[2, 3, 1], [2, 3, 1], [2, 3, 1], [2, 3, 1]]
#[[3, 1, 2], [3, 1, 2], [3, 1, 2], [3, 1, 2], [3, 1, 2]]
#[[3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1]]
#[[], [], [], [], [], []]
I have no idea why the list 'res' defined in main() wont be updated when we pass it to a recursive function. Any suggestion about how to update 'res'?