Skip to content

Instantly share code, notes, and snippets.

@dreamersdw
Created September 18, 2013 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreamersdw/6609989 to your computer and use it in GitHub Desktop.
Save dreamersdw/6609989 to your computer and use it in GitHub Desktop.
def permutations(seq):
if not seq:
yield []
else:
for i in xrange(len(seq)):
for p in permutations(seq[1:]):
yield p[0:i] + [seq[0]] + p[i:]
for p in permutations([1, 2, 3, 4]):
print p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment