Skip to content

Instantly share code, notes, and snippets.

@cadl
Last active December 23, 2015 08:39
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 cadl/6609683 to your computer and use it in GitHub Desktop.
Save cadl/6609683 to your computer and use it in GitHub Desktop.
all_permutation
def all_perm(l):
if not l:
return [[]]
return [[a] + b for a in l for b in all_perm(_remove(l, a))]
def _remove(l, item):
tmp = l[:]
tmp.remove(item)
return tmp
>>> all_perm([1, 2, 3, 4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment