1 | def set_dictionary(filename): |
2 | global dictionary |
3 | dictionary = open(filename) |
4 | dictionary = dictionary.read() #dictionary is now a string of dictionary words |
5 | |
6 | def text(t): |
7 | """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 |
8 | """ |
9 | import re |
10 | misspelled = [] |
11 | dict = dictionary |
12 | pat = re.compile('\n') |
13 | dict = pat.sub(' ', dict) |
14 | dict = dict.split() #dict is now a sequence of dictionary words |
15 | |
16 | for word in t: |
17 | 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 |
18 | misspelled.insert(0, word) #add the word to the misspelled list |
19 | |
20 | return misspelled |