Skip to content

Instantly share code, notes, and snippets.

@anddam
Last active January 14, 2017 09:42
Show Gist options
  • Save anddam/f2c1f1945be039d7eff4a2c59cd5d5b9 to your computer and use it in GitHub Desktop.
Save anddam/f2c1f1945be039d7eff4a2c59cd5d5b9 to your computer and use it in GitHub Desktop.
def permutate(string):
"Generate permutations of a string"
if not string:
yield ''
for head in string:
for tail in permutate([l for l in string if l != head]):
yield head + tail
print(list(permutate('ABC')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment