Last active
March 8, 2018 09:39
-
-
Save jmuzsik/38cf910d620f14147307b65b52efffe7 to your computer and use it in GitHub Desktop.
This file contains 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 anagrams(s): | |
if s == "": | |
return [s] | |
else : | |
ans = [] | |
for w in anagrams(s[1: ]): | |
for pos in range(len(w) + 1): | |
ans.append(w[: pos] + s[0] + w[pos: ]) | |
return ans | |
anagrams("abc") | |
# returns ['abc', 'bac', 'bca', 'acb', 'cab', 'cba'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment