In: Computer Science
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the given wordlist An anagram dictionary has each word with the letters sorted alphabetically creating a “key”.
Python code:
#defining anagramdictionary function
def anagramdictionary(wordlist):
#creating an empty dictionary
dic={}
#looping each word in list
for i in wordlist:
#sorting each letters in word and adding the key value pair
dic["".join(sorted(i))]=i
#returnining the dictionary
return dic
#calling anagramdictionary function and printing result for sample
value
print(anagramdictionary(['hello','i','am','rahul']))
Screenshot:
Output: