def anagrams (string) : """ Given a word an anagram is formed by rearranging the letters of the word. This function takes a string as parameter and is supposed to compute a list of all anagrams of this string. """ # base case if string == "": return [string] # recursive case # Computes all anagrams for the string without the first letter. Then, # takes each of these anagrams and adds the first letter at each possible # position. else: answer = [] for word in anagrams(string[1:]): for pos in range(0,len(word)): answer.append(word[:pos]+string[0]+word[pos:]) return answer