-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.py
More file actions
52 lines (40 loc) · 1.56 KB
/
Copy pathDictionary.py
File metadata and controls
52 lines (40 loc) · 1.56 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
47
48
49
50
51
52
import json
from difflib import get_close_matches
data = json.load(open("Application1_Dictionary/data.json"))
def meaning (w):
#w.lower() - this is to show that w.lower() needs to be stored in w
#print (w)
w = w.lower()
#if w == data.keys():
if w in data.keys():
#a1 = data[w]
#print (*a, sep = '\n')
return data[w]
elif w.title() in data.keys():
return data[w.title()]
elif w.upper() in data.keys():
return data[w.upper()]
elif len(get_close_matches(w, data.keys())) > 0:
user = input (f"Did you mean {get_close_matches(w, data.keys())[0]}? \n Y or N: ")
if user.upper() == "Y":
#a2 = data[get_close_matches(w, data.keys())[0]]
#print (*a2, sep = '\n')
return data[get_close_matches(w, data.keys())[0]]
elif len(get_close_matches(w, data.keys())) > 1:
user2 = input (f"Did you mean {get_close_matches(w, data.keys())[1]}? \n Y or N: ")
if user2.upper() == "Y":
#a3 = data[get_close_matches(w, data.keys())[1]]
#print (*a3, sep = '\n')
return data[get_close_matches(w, data.keys())[1]]
else:
return("We did not understand your query, please try again.")
else:
return ("Word did not found")
word = input ("Enter a word whose meaning you want to find: ")
output = meaning (word)
#if type (output) == list:
if isinstance (output, list):
for i in output:
print (i)
else:
print (output)