| 1 | import re |
| 2 | |
| 3 | dictionary = {} |
| 4 | file = open('dict.txt') |
| 5 | for word in file: |
| 6 | dictionary[word.strip()] = 1 |
| 7 | file.close() |
| 8 | |
| 9 | junkpat = re.compile(r'[",.:;!?()]') |
| 10 | wordpat = re.compile(r'^[a-zA-Z\']+$') |
| 11 | |
| 12 | def clean_word(word): |
| 13 | """Remove punctuation from a word and return the cleaned word.""" |
| 14 | return junkpat.sub('', word) |
| 15 | |
| 16 | def is_checkable_word(word): |
| 17 | """Return true if the given string is a checkable word.""" |
| 18 | return wordpat.match(word) |
| 19 | |
| 20 | def dictionary_contains(word): |
| 21 | """Return true if the given word is in the dictionary.""" |
| 22 | return word in dictionary or word.lower() in dictionary |