-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive_dictionay.py
47 lines (30 loc) · 1.06 KB
/
interactive_dictionay.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Created on Mon Jun 15 18:45:24 2020
@author: manish kumar
"""
import json
from difflib import SequenceMatcher as sm
from difflib import get_close_matches as matches
with open (r"D:\Tutorials\New folder\08 Application 1 Building an Interactive Dictionary\data.json") as f:
data = json.load(f)
input_word = input(" Enter a Word.. ")
print(input_word)
def meaning(word):
word=word.lower()
if word in data:
output = data[word]
return output
elif len(matches(word,data.keys())) > 0:
yn = input("did you mean %s instead ?? _______ enter Y if yes, or no N if not " % matches(word, data.keys()) [0] )
print(yn)
if yn == "y" :
return data[matches(word, data.keys())[0]]
elif yn == 'n':
print("no match found")
else: return "We dont understand the entry !!!"
else:
return "word doesn't exist++double check it.."
output= meaning(input_word)
if type(output) == list:
for i in output:
print(i)