How To Make a English English Dictionary Using Python?
Code:
import json
from difflib import get_close_matches
data=json.load(open("D:\classroom\python\dictionry prog\data.json"))
def translate(word):
word=word.lower()
if word in data:
return data[word]
elif get_close_matches(word,data.keys())!=[]:
if get_close_matches(word,data.keys())[0] in data:
print("did you mean %s : " %get_close_matches(word,data.keys())[0])
yn=input("type Y for Yes and N for No : ")
if yn=='y' or yn=='Y':
word=get_close_matches(word,data.keys())[0]
return data[word]
elif yn=='n' or yn=='N':
print("OK , pls check the word again...")
return []
else:
print("pls give a valid option")
return []
else:
print("word does not exist")
return []
while True:
print("\end : exit")
word=input("enter a word: ")
if word!="\end":
out=translate(word)
for i in out:
print(i)
else:
break
Here we are used a file data.json as the source for our dictionary. Download this file from here.