Skip to content

Instantly share code, notes, and snippets.

@prat0318
Created December 16, 2013 05:48
Show Gist options
  • Save prat0318/7982859 to your computer and use it in GitHub Desktop.
Save prat0318/7982859 to your computer and use it in GitHub Desktop.
Find all permutations
def print_permutations(str):
if(len(str) == 1): return [str]
perms = print_permutations(str[1:])
return [x[0:i]+str[0]+x[i:] for x in perms for i in range(len(x)+1)]
print print_permutations("abc")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment