import re dictionary = {} file = open('dict.txt') for word in file: dictionary[word.strip()] = 1 file.close() junkpat = re.compile(r'[",.:;!?()]') wordpat = re.compile(r'^[a-zA-Z\']+$') def clean_word(word): """Remove punctuation from a word and return the cleaned word.""" return junkpat.sub('', word) def is_checkable_word(word): """Return true if the given string is a checkable word.""" return wordpat.match(word) def dictionary_contains(word): """Return true if the given word is in the dictionary.""" return word in dictionary or word.lower() in dictionary