Last active
December 23, 2015 08:39
-
-
Save cadl/6609683 to your computer and use it in GitHub Desktop.
all_permutation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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