Skip to content

Instantly share code, notes, and snippets.

@colyk
Created July 6, 2017 20:52
Show Gist options
  • Save colyk/1e97aea9900c723b576ac81a385b9932 to your computer and use it in GitHub Desktop.
Save colyk/1e97aea9900c723b576ac81a385b9932 to your computer and use it in GitHub Desktop.
Пермутация символов в строке
def permutations(s):
if len(s) <= 1:
return [s]
else:
perms = []
for e in permutations(s[:-1]):
for i in range(len(e)+1):
perms.append(e[:i] + s[-1] + e[i:])
return perms
print(permutations('123'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment