##open file and create a dictionary of {"word":"sorted word"} word_file = open("word_list(1).txt","r") word_list = {} for text in word_file: simple_text = ''.join(sorted(text.lower().strip())) word_list.update({text.lower().strip():simple_text}) ##lowercase and sort the user input word def simplify_entered_word(): lower_word = ''.join(sorted(input_word.lower().strip())) #Creates a list with the lowercase, sorted letters. return lower_word #Compare the sorted user input with the values of the dictionary to find the anagrams. def find_in_dict(entered_word): for key,val in word_list.items(): if val == entered_word: print(key,input_word) ##main loop while True: input_word = input("Input the word for anagram checking: ") find_in_dict(simplify_entered_word())