Permutations algoritm?

Patrick W patrickw106 at yahoo.com.au
Fri Nov 15 21:20:10 EST 2002


sismex01 at hebmex.com writes:

> Does anybody have a clear, simple, permutations algorithm
> in Python?

Since you've already received sensible answers, this one's just for fun.

def perm(s):
    return [[s[i]] + x \
            for i in range(len(s)) \
            for x in perm(s[:i] + s[i+1:])] or [[]]

Can anyone come up with a shorter one?



More information about the Python-list mailing list