# David Wallace # Homework 3.1: check spelling of words in input.txt # Unfortunately I didn't find a partner, so # I wrote 'speling' first, then the checker of 'input.txt'. import speling def checkfile(filename): """Show spelling mistakes in a file""" infile = open(filename, 'r') words = speling.split_text_to_words(infile.read()) # find and count all the misspelled words print "checking spelling... (%d words)" % len(words) misspellings = {} for ii in range(len(words)): if ii%10==0: print ii, # print progress as we go word = words[ii] if not speling.correct(word): if word in misspellings: misspellings[word] += 1 else: misspellings[word] = 1 # print results print "\n\nmisspelled words:" results = misspellings.items() results.sort() for (word, num) in results: print '%s (%d)' % (word, num) # gentlemen, start your engines. checkfile('input.txt')