In preparation for a job interview I decided to try and implement the classic find all anagrams of a given string solution. I wanted to see if I could translate a javascript solution into python. This was my attempt:
def anagrams(word):
if len(word) < 2:
return word
else:
tmp = []
for i, letter in enumerate(word):
for j in anagrams(word[:i]+word[i+1:]):
tmp.append(j+letter)
return tmp
if __name__ == "__main__":
print anagrams("abc")
word
. \$\endgroup\$