Files
wordle/dictionary.py
T

91 lines
1.5 KiB
Python

#!/usr/bin/python
import h5py
WORDLE_LENGTH = 5
_invalid_words = set(
[
"amala",
"arara",
"araru",
"araua",
"arawa",
"balak",
"batak",
"bayal",
"beala",
"beata",
"beele",
"boily",
"bolty",
"bruke",
"carlo",
"caroa",
"carot",
"carum",
"divet",
"doray",
"erept",
"fikie",
"genae",
"ghole",
"gotra",
"hirse",
"hyrse",
"katat",
"korah",
"macco",
"mitra",
"muang",
"nurry",
"odell",
"odell",
"petro",
"pindy",
"quito",
"retan",
"roter",
"sisel",
"skeel",
"staia",
"stail",
"sussy",
"tebet",
"telae",
"theet",
"undig",
"uninn",
"unkin",
"vedet",
"whalm",
"whaly",
]
)
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():
return WordleWords(filename="dictionary.hdf5")