Permutation Generator

David Isaac aisaac0 at
Sat Aug 13 22:24:43 CEST 2005

"Talin" <talin at> wrote in message
news:mailman.3042.1123875574.10512.python-list at
> I wanted to share
> this: a generator which returns all permutations of a list:

Try this instead:
def permuteg(lst): return ([lst[i]]+x
       for i in range(len(lst))
       for x in permute(lst[:i]+lst[i+1:])) \
       or [[]]

Alan Isaac

More information about the Python-list mailing list