From e6af2d3e7ad3950732629536836f3845c4c5ede5 Mon Sep 17 00:00:00 2001 From: Venkat Kiran <83776415+venkatkiran343@users.noreply.github.com> Date: Sat, 16 Oct 2021 10:49:30 +0530 Subject: [PATCH] Create English-dictionary-application --- English-dictionary-application | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 English-dictionary-application diff --git a/English-dictionary-application b/English-dictionary-application new file mode 100644 index 0000000..0a7f996 --- /dev/null +++ b/English-dictionary-application @@ -0,0 +1,36 @@ +import json +from difflib import get_close_matches + +# Loading data from json file +# in python dictionary +data = json.load(open("dictionary.json")) + +def translate(w): + # converts to lower case + w = w.lower() + + if w in data: + return data[w] + # for getting close matches of word + elif len(get_close_matches(w, data.keys())) > 0: + yn = input("Did you mean % s instead? Enter Y if yes, or N if no: " % get_close_matches(w, data.keys())[0]) + yn = yn.lower() + if yn == "y": + return data[get_close_matches(w, data.keys())[0]] + elif yn == "n": + return "The word doesn't exist. Please double check it." + else: + return "We didn't understand your entry." + else: + return "The word doesn't exist. Please double check it." + +# Driver code +word = input("Enter word: ") +output = translate(word) + +if type(output) == list: + for item in output: + print(item) +else: + print(output) +input('Press ENTER to exit')