-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (24 loc) · 795 Bytes
/
main.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
from time import perf_counter
from trie import trieDS
def main():
print("Initializing data-structure")
init_start_time = perf_counter()
trie = trieDS()
with open("words_alpha.txt", "r") as f:
lines = f.readlines()
for word in lines:
trie.add_word(word.strip())
word_count = len(lines)
del lines
init_fin_time = perf_counter()
print(f"Initialization ready. Took {init_fin_time - init_start_time} seconds")
print(f"Added {word_count} words.")
while True:
word_to_check = input("Check if word exists: ")
res = trie.find_word(word_to_check)
if res:
print(f"{word_to_check} is a word!\n")
else:
print(f"{word_to_check} is not a word\n")
if __name__ == "__main__":
main()