-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
33 lines (29 loc) · 969 Bytes
/
app.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
# Dynamic Dictionary
import json
import difflib as dl
data = json.load(open("data.json"))
def translate(word):
if word.lower() in data:
return data[word.lower()]
elif word.capitalize() in data:
return data[word.capitalize()]
elif word.upper() in data:
return data[word.upper()]
elif len(dl.get_close_matches(word, list(data), cutoff=0.7)) > 0:
matches = dl.get_close_matches(word, list(data), cutoff=0.7)[0]
yes_no = input(f"Did you mean {matches} instead? ").lower()
if yes_no == "y":
return data[matches]
elif yes_no == "n":
return "Please try again with another word"
else:
"You didn't answer with 'y' or 'n'. Please run the program again"
else:
return "Word not found. Please try again! "
query = input("Enter word: ")
output = translate(query)
if type(output) == list:
for l in output:
print(l)
else:
print(output)