def fp(n):
"""find full permutation for 1-n,
using swapping method."""
orig = range(1, n+1)
perm = [list(orig)]
for i in orig[:n]:
for j in orig[i:n]:
temp = list(orig)
temp[i-1], temp[j-1] = temp[j-1], temp[i-1]
perm.append(temp)
return perm
网友评论