def do_nothing(): return 5 file = open("input.txt") mispell = {} ##### Dictionary for holding the mispelt words and the number of times they appear for current_line in file: word_list = current_line.split() list_len = word_list.__len__() for i in range(list_len): ##### for each word in the line current_word = word_list.__getitem__(i) if current_word.endswith('.') | current_word.endswith(','): ##### for removing punctuation marks current_word = current_word[0:current_word.__len__()-1] if test_word(current_word): ###### Using Scott's function for checking if the word exists. do_nothing() else: ###### if the word does not exist then put in in the mispell dictionary if current_word in mispell: ###### if the word is already in the dictionary, simply increment counter temp = mispell[current_word] mispell[current_word] = temp + 1 else: mispell[current_word] = 1 ##### Move the words into a list, and then alphabetically sort the list word_list2 = [] for i in mispell: word_list2.append(i) word_list2.sort() ##### Write the output into a file output_file = open("output.txt", 'w'); for i in word_list2: x = i + " " + "(" + str(mispell[i]) + ")" + "\n" output_file.write(x) output_file.flush() output_file.close()