Skip to content

Instantly share code, notes, and snippets.

@napratin
Last active January 2, 2016 10:39
Show Gist options
  • Save napratin/8291279 to your computer and use it in GitHub Desktop.
Save napratin/8291279 to your computer and use it in GitHub Desktop.
Permutations in Python
def permutations(s):
"""Return all permutations of the characters in a string."""
res = []
for i in xrange(len(s)):
c = s[i]
rem = s[:i] + s[i+1:]
if rem:
temp = permutations(rem)
res += [c + t for t in temp]
else:
res += c
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment