Skip to content

Instantly share code, notes, and snippets.

@Tsunamicom
Created February 23, 2016 16:56
Show Gist options
  • Save Tsunamicom/f48b1c093b2466f59042 to your computer and use it in GitHub Desktop.
Save Tsunamicom/f48b1c093b2466f59042 to your computer and use it in GitHub Desktop.
Python permutations
def perm(text):
if len(text) == 1:
return [text]
else:
sub_perm = perm(text[1:])
first = text[0]
permutations = list()
for subset in sub_perm:
for i in range(len(subset)+1):
permutations.append(subset[:i]+ first+subset[i:])
return permutations
print(perm('1234'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment