Merge pull request #46 from Stack-of-Pancakes/dwyl-merge

Refactored the python code example
This commit is contained in:
Nelson 2018-05-19 20:31:29 +01:00 committed by GitHub
commit 759c4b3e2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,16 +1,11 @@
import json
import os, sys
def load_words():
try:
filename = os.path.join(os.getcwd(), "words_dictionary.json")
with open(filename,"r") as english_dictionary:
valid_words = json.load(english_dictionary)
return valid_words
except Exception as e:
return str(e)
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(english_words["fate"])
print('fate' in english_words)