Refactor, breaking code into modules.
This commit is contained in:
1 parent
2f14532ef1
commit
0639113205
11 files changed
+312
-178
No files matched your search
+22
-11
@@ -1,5 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import h5py
|
||||
|
||||
WORDLE_LENGTH = 5
|
||||
|
||||
|
||||
@@ -63,17 +65,26 @@ _invalid_words = set(
|
||||
)
|
||||
|
||||
|
||||
_wordle_dictionary = set()
|
||||
class WordleWords:
|
||||
_words = set()
|
||||
|
||||
def __init__(self, filename):
|
||||
if not self._words:
|
||||
with open("words_alpha.txt") as word_file:
|
||||
all_words = word_file.read().split()
|
||||
self._words.update(
|
||||
filter(
|
||||
lambda w: len(w) == WORDLE_LENGTH and w not in _invalid_words,
|
||||
all_words,
|
||||
)
|
||||
)
|
||||
|
||||
def _initialize_db(self):
|
||||
pass
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._words)
|
||||
|
||||
|
||||
def words():
|
||||
if not _wordle_dictionary:
|
||||
with open("words_alpha.txt") as word_file:
|
||||
all_words = word_file.read().split()
|
||||
_wordle_dictionary.update(
|
||||
filter(
|
||||
lambda w: len(w) == WORDLE_LENGTH and w not in _invalid_words, all_words
|
||||
)
|
||||
)
|
||||
|
||||
return _wordle_dictionary
|
||||
return WordleWords(filename="dictionary.hdf5")
|
||||
Reference in new issue
Block a user