Permutation Generator

David Isaac aisaac0 at verizon.net
Sat Aug 13 16:24:43 EDT 2005


"Talin" <talin at acm.org> wrote in message
news:mailman.3042.1123875574.10512.python-list at python.org...
> 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