-
Notifications
You must be signed in to change notification settings - Fork 4
/
E2E_dictionary.py
30 lines (29 loc) · 1.04 KB
/
E2E_dictionary.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
import json
from difflib import get_close_matches
data= json.load(open("data.json"))
def dictionary(word):
word=word.lower()
if word in data:
return data[word]
elif len(get_close_matches(word,data.keys()))>0:
response=input("Did you mean" +%s+" instead? If yes enter Y else N for no: "% get_close_matches(word,data.keys())[0])
if response =='Y' or response =='y':
return data[get_close_matches(word,data.keys())[0]]
elif response == 'N'or response == 'n':
return "Word does not exist, plz double check it"
else:
return "We did not get you"
else:
return ("Word does not exist. Please double check it! ")
while True:
word=input("Search your word: ")
result=dictionary(word)
if type(result) == list:
for item in result:
print(item)
else:
print(result)
demand=input("To close type 'Y' else 'N': ")
if demand == 'Y' or demand =='y':
print("Hope you visit again")
break