english-words/read_english_dictionary.py
Stack-of-Pancakes fd2f8a6179 Refactor python code example
sys imported and unused.
os only used to create cwd which is implied with open
try/except block that doesn't handle anything
json loaded to create a more expensive defaultdict
dict created just for membership testing instead of set
membership test performed by fetching key value instead of using in
2018-04-29 15:33:04 -04:00

12 lines
255 B
Python

def load_words():
with open('words_alpha.txt') as word_file:
valid_words = set(word_file.read().split())
return valid_words
if __name__ == '__main__':
english_words = load_words()
# demo print
print('fate' in english_words)