From 71d073dc3cd779cc44e2bc6c03793143e51d4e69 Mon Sep 17 00:00:00 2001 From: aliza321 <53407463+aliza321@users.noreply.github.com> Date: Sun, 13 Oct 2019 23:52:59 +0530 Subject: [PATCH] Add files via upload --- libdict.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 libdict.py diff --git a/libdict.py b/libdict.py new file mode 100644 index 0000000..7e36081 --- /dev/null +++ b/libdict.py @@ -0,0 +1,30 @@ +import json +from difflib import get_close_matches +data = json.load(open("data.json")) + +def definition(w): + w = w.lower() + if w in data: + return data[w] + elif w.title()in data: + return data[w.title()] + elif w.upper()in data: + return data[w.upper()] + elif len(get_close_matches(w,data.keys())) > 0: + yn=input("did you mean %s . enter Y if yea and N if no" % get_close_matches(w, data.keys())[0]) + if yn == "Y": + return data[get_close_matches(w, data.keys())[0]] + elif yn == "N": + return"The word doesnt exist in dictionary" + else: + return "did not understand" + else: + return "The word doesnt exist in dictionary" + +word = input("enter word to be searched ") +op = definition(word) +if type(op) == list: + for item in op: + print(item) +else: + print(op) \ No newline at end of file