I have written a code of permutation, when subarr.remove(set[i]) is executed, the store is getting automatically updated and value is getting removed from the list; and in end, output is returning as lists of empty lists. Can anyone please check and tell me why this is happening and how to correct it in the existing code? Thanks in advance.
def perm(n, set, subarr, map, store):
if len(subarr) == n:
store += [subarr]
else:
for i in range(n):
if set[i] not in map:
map.append(set[i])
subarr.append(set[i])
perm(n, set, subarr, map, store)
map.remove(set[i])
subarr.remove(set[i])
return store
set = [1, 2, 3]
n = len(set)
subarr = []
map = []
store = []
print(perm(n, set, subarr, map, store))