import speling.py import string if import_entries('dict.txt') != 0 return "Exiting program, no dictionary file" myFile = open("doc.txt") correctionList = [] for line in myFile: # Works at word-level via line-by-line feed of file x = line.split() for word in x: # Strips off non-alphanumeric & non-apostrophe characters y = "" for c in word: if (c <= 'z') or (c == "'"): y = y + c # Checks the word against dictionary if (check_word(string.lower(y)) != []) or (check_word(y) != []): # good word, skip else: # add it to the list of misspelled words correctionList.extend(y) # At this point, we have a list of misspelled words, with duplications # thus, we can make a function that will collect the duplicates def count(myList): d = {} # Initializes dictionary for c in myList: d[c] = 0 for c in myList: d[c] = d[c] + 1 return d # Use a dictionary to collect the duplicates. z = count(correctionList) # Make list so we an sort it and print a = [] for key in z: a.extend(key + " (" + z[a] + ") \n") print a.sort()