In the following algorithm when I am using permutation.append(array) in base case it just copies around the same thing. But when I try array[:] which I think is the same thing it works correctly. I am not sure for the reason. Can someone explain what's going on
def getPermutations(array):
# Write yor code here.
permutation=[]
perm(0, array, permutation)
print(permutation)
return permutation
def perm(i, array, permutation):
if i==len(array)-1:
print(array)
permutation.append(array)
print(permutation)
else:
for j in range(i, len(array)):
swap(array,i,j)
perm(i+1, array, permutation)
swap(array,i,j)
def swap(array, i, j):
array[i], array[j]=array[j], array[i]