To make a shallow copy, you can slice the list:
newprefix = prefix[:]
Or pass it to the list constructor:
newprefix = list(prefix)
Also, I think you can simplify your code a bit:
def perm(prefix, rest): print prefix, rest for i in range(len(rest)): perm(prefix + [rest[i]], rest[:i] + rest[i + 1:]) perm([], ['a','b','c'])
Blender Apr 29 '13 at 2:26 am 2013-04-29 02:26
source share