-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoading Data.py
More file actions
28 lines (24 loc) · 758 Bytes
/
Loading Data.py
File metadata and controls
28 lines (24 loc) · 758 Bytes
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
import json
from difflib import get_close_matches
data = json.load(open('datajson.json'))
def translate(w):
w = w.lower()
if w in data:
return data[w]
elif len(get_close_matches(w, data.keys(), cutoff=0.8)) > 0 :
yn = input("Did you mean %s instead ? Enter Y if yes, or N if no :" %get_close_matches(w, data.keys())[0])
if yn == "Y":
return data[get_close_matches(w, data.keys())[0]]
elif yn == "N" :
return "Word Doesn't Exist"
else :
return "Provide the right input"
else:
return "Word Doesn't Exist"
word = input("Enter any word: ")
output = translate(word)
if type(output) == list:
for item in output:
print(item)
else:
print(output)