Skip to content

Instantly share code, notes, and snippets.

@interstar
Created February 25, 2012 00:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save interstar/1904824 to your computer and use it in GitHub Desktop.
Save interstar/1904824 to your computer and use it in GitHub Desktop.
Python Permutation Generator : A generator that outputs all permutations of a sequence
def perm(xs) :
if xs == [] :
yield []
for x in xs :
ys = [y for y in xs if not y==x]
for p in perm(ys) :
yield ([x] + p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment