Skip to content

Instantly share code, notes, and snippets.

@zhy0216
Last active August 29, 2015 14:04
Show Gist options
  • Save zhy0216/ed2cb6d57671b3701b72 to your computer and use it in GitHub Desktop.
Save zhy0216/ed2cb6d57671b3701b72 to your computer and use it in GitHub Desktop.
permutation.py
def gen_permutation(string):
if len(string) == 1:
yield string
for char in string:
rest = string.replace(char, "")
for p_string in gen_permutation(rest):
yield char + p_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment