-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary.py
36 lines (28 loc) · 999 Bytes
/
dictionary.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
import json
import difflib
from difflib import get_close_matches
#>SequenceMatcher(None, "rain", "rainn").ratio()
#to get ratio of how similar the words are
#get_close_matches
data = json.load(open("dictionary.json"))
def define(word):
word = word.lower()
if word in data:
return data[word]
elif len(get_close_matches(word, data.keys())) > 0:
yn = input("Did you mean: %s instead? Enter Y if yes, or N if no: " % get_close_matches(word,data.keys())[0])
if yn == "Y":
return data[get_close_matches(word, data.keys())[0]]
elif yn =="N":
return "The word doesn't exist. Please double check it."
else:
return "I'm not sure what you mean."
else:
print("This word doesn't exist.")
word = input("Enter the word that you want to search for: ")
output = (define(word))
if type(output) == list:
for item in output:
print(item)
else:
print(output)