Skip to content

Instantly share code, notes, and snippets.

@dagoof
Created November 3, 2010 12:37
Show Gist options
  • Save dagoof/661030 to your computer and use it in GitHub Desktop.
Save dagoof/661030 to your computer and use it in GitHub Desktop.
def permute(queue, final = []):
for item in queue:
remaining_queue, pending = [e for e in queue if e is not item], final + [item]
if remaining_queue:
for more in permute(remaining_queue, pending):
yield more
else:
yield pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment