Skip to content

Instantly share code, notes, and snippets.

@yasith
Created April 19, 2012 19:22
Show Gist options
  • Save yasith/2423431 to your computer and use it in GitHub Desktop.
Save yasith/2423431 to your computer and use it in GitHub Desktop.
Permutations
def permute(L):
if len(L) == 1:
return [L]
ret = []
for i in range(len(L)):
X = permute(L[:i] + L[i+1:])
for sub_list in X:
ret.append([L[i]] + sub_list)
return ret
if __name__ == '__main__':
print permute([1,2])
print permute([1,2,3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment