def set_dictionary(filename): global dictionary dictionary = open(filename) dictionary = dictionary.read() #dictionary is now a string of dictionary words def text(t): """takes a list of words with punctuation removed, returns a list of all words that are not in dictionary (in the reverse order they appeared in the text """ import re misspelled = [] dict = dictionary pat = re.compile('\n') dict = pat.sub(' ', dict) dict = dict.split() #dict is now a sequence of dictionary words for word in t: if dict.count(word) == 0 and dict.count(word.lower()) == 0: #if the word is not in the dictionary the way it appears or in lower case misspelled.insert(0, word) #add the word to the misspelled list return misspelled