Skip to content

Instantly share code, notes, and snippets.

@kflu
Created June 27, 2012 01:07
Show Gist options
  • Save kflu/3000608 to your computer and use it in GitHub Desktop.
Save kflu/3000608 to your computer and use it in GitHub Desktop.
Calculate all string permutation
def strperm(S):
if not S: yield ""
for c in S:
for perm in strperm(S - set([c])):
yield c + perm
for s in strperm(set("abcd")):
print s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment