# Thanh Thai # cs198-ak # Text_processing.py #Part Uno: import speling.py def count(asequence): """ Counts the number of time an item appear int he sequence """ dictionary = {} times = len(asequence) while times > 0: last_item = asequence[times-1] if dictionary.get(last_item) == None: counter = asequence.count(last_item) dictionary[last_item] = counter times = times - 1 else: times = times-1 return dictionary def print_result(a_dictionary): """ Print the result of spell_check in an alphabetical order """ keylist = a_dictionary.keys() keylist.sort() for key in keylist: print key, '(' , a_dictionary[key], ')' def spell_check(input.txt): """ Spellcheck a file """ file = open('input.txt') misspelled_wds = [] for line in file: wd_list = speling.parseWords(line) for each_wd in wd_list: if speling.checkspelling(each_wd) == None: misspelled_wds.append(each_wd) print_result(count(misspelled_wds)) # Part Dos: # I had to assume that the speling.checkspelling(word) will return the word/value if the the word # is found in the dictionary, and return None otherwise.