-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
28 lines (24 loc) · 850 Bytes
/
dictionary.py
File metadata and controls
28 lines (24 loc) · 850 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
28
import json
from difflib import get_close_matches
data = json.load(open("data.json"))
def getMeaning(word):
word = word.lower()
if word in data:
return data[word]
elif len(get_close_matches(word, data.keys())) > 0:
yn = input("Do you mean %s ? if yes then press Y otherwise N : " % get_close_matches(word, data.keys())[0])
if yn == "Y":
return data[get_close_matches(word, data.keys())[0]]
elif yn == "N":
return "Your word is not %s " % get_close_matches(word, data.keys())[0]
else :
return "We couldn't understand!"
else:
return "The word you entered is not existed. Please double check it."
word = input("Enter a word : ")
output = getMeaning(word)
if type(output) == list:
for item in output:
print(item)
else:
print(output)