-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive_dict.py
More file actions
47 lines (37 loc) · 1.26 KB
/
Copy pathinteractive_dict.py
File metadata and controls
47 lines (37 loc) · 1.26 KB
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
import json
import difflib
from difflib import SequenceMatcher
from difflib import get_close_matches
data=json.load(open("C:/Python36/working_files/data.json")) #data.json file has been uploaded in read mode
'''print (data)
print("\n")
print(type(data))
print(data["rain"])
'''
def translate(word):
word=word.lower()
if(word in data):
return data[word]
elif(word.capitalize() in data):
return data[word.capitalize()]
elif len(get_close_matches(word, data.keys(), cutoff=0.8))>0:
print( "Did you mean %s instead? " % get_close_matches(word, data.keys(), cutoff=0.8)[0])
yesorno=input("y or n : ")
if (yesorno=='y'):
return data[get_close_matches(word, data.keys(), cutoff=0.8)[0]]
elif(yesorno=='n'):
return "Sorry, We dont know what you are trying to search for"
else:
return "Sorry!, we don't know what you are trying to do"
else:
return "Sorry, We dont know what you are trying to search for"
ch='y'
while(ch=='y'):
word=input("Enter word:")
output=translate(word)
if type(output)==list:
for item in output:
print (item)
else :
print(output)
ch=input("\nDo you want to search for more words? (y or n) :")