def test_letters(s1,s2):
s1 = sorted(s1.lower())
s2 = sorted(s2.lower())
return s1 == s2
def word_anagrams(string,wordbook):
anagrams_list = []
for word in wordbook:
if test_letters(string, word):
anagrams_list.append(word)
return anagrams_list
str = input("Enter string : ")
wordbook = []
with open("abc.txt", "r") as data:
for line in data:
word = line.strip()
wordbook.append(word)
print(word_anagrams(str,wordbook))
Output screenshot:
NOTE: YOU MUST MENTION YOUR FILENAME IN PLACE OF abc.txt .
If any problems occur contact me. Thanks
Get Answers For Free
Most questions answered within 1 hours.