-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathWordList.py
26 lines (20 loc) · 829 Bytes
/
WordList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import string
class WordList:
"""
Reads a list of words from a file and filters it for wordle compatible words.
Used to provide word list copies.
"""
def __init__(self, filename):
self.ascii_lowercase = list(string.ascii_lowercase)
with open(filename, encoding="utf8") as file:
self.words = file.readlines()
self.words = [word.rstrip() for word in self.words]
self.words = [w for w in self.words if len(w) == 5 and self.is_ascii_lowercase(w)]
self.words = list(dict.fromkeys(self.words)) # remove duplicates
def get_list_copy(self):
return self.words.copy()
def is_ascii_lowercase(self, word):
for letter in word:
if letter not in self.ascii_lowercase:
return False
return True