[Pythonmac-SIG] permutation of lists

the hafler trio h3o@veda.is
Thu, 26 Nov 1998 11:10:54 -0500


helloo.

I have a situation where I wish to permutate a list in all its possible
combinations, given that one can compute the number of permutations with
the formula as so:

given a list with 5 elements, the number of permutations = 1x2x3x4x5.

here is the definition file:

def permute(list):
	if not list:
		return [list]
	else:
		res = []
		for i in range(len(list)):
			rest = list[:i] + list[i+1:]
			for x in permute(rest):
				res.append(list[i:i+1] + x)
			return res

then, I import....
which gives simply:

>>> from permcomb import *
>>> permute([1,2,3])
[[1, 2, 3]]


which is quite obviously not what I am after. this works on a Linux box.
why, then, not on the Mac?

can anyone enlighten me here?

best

andrew mckenzie