[Pythonmac-SIG] permutation of lists

Just van Rossum just@letterror.com
Thu, 26 Nov 1998 18:02:20 +0100


At 11:10 AM -0500 11/26/98, the hafler trio wrote:
>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?

You don't use any platform-specific features, so logically it is not
possible that this works on Linux and not on the Mac. Why don't you run
through the program using the debugger in the IDE?

Just