-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword.py
47 lines (40 loc) · 1.71 KB
/
word.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import numpy as np
import platform
class Word:
@staticmethod
def get_the_dictionary_for_words() -> dict:
"""The purpose of this method is to load words to dictionary with key of first letter
PARAMETERS:
None
RETURNS:
loaded_dictionary: dict
It returns dict with key as a single letter and value is a list of words starting with this letter"""
loaded_dictionary = {}
for i in range(65, 91):
letter = "{}".format(chr(i))
try:
loaded_dictionary.update({letter: np.genfromtxt(Word.get_path_for_divided(chr(i)), dtype=str)})
except Exception as e:
print("{}.txt doesn't exist in this directory".format(chr(i)))
return loaded_dictionary
@staticmethod
def check_validity_of_word(word: str, loaded_dictionary: dict) -> bool:
word = word.upper()
letter = word[0]
# print(os.getcwd())
if word in loaded_dictionary.get(letter):
return True
else:
return False
# It is the path to the specific file depending on the first letter of the word
@staticmethod
def get_path_for_divided(starting_letter: str) -> str:
# print(os.getcwd())
_platform = platform.system()
if _platform == "Windows":
path_of_main_dict = "{}{}".format(os.getcwd(), "\\dict_for_game")
return "".join([path_of_main_dict, "\\divided_dict", "\\", starting_letter, ".txt"])
elif _platform == "Darwin":
path_of_main_dict = "{}{}".format(os.getcwd(), "/dict_for_game")
return "".join([path_of_main_dict, "/divided_dict", "/", starting_letter, ".txt"])