Created
July 6, 2017 20:52
-
-
Save colyk/1e97aea9900c723b576ac81a385b9932 to your computer and use it in GitHub Desktop.
Пермутация символов в строке
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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