forked from Atharv-Attri/HacktoberFest-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fredcodee/fredcodee-python-dictionary-1
dictionary app added to python projects
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import json | ||
#python module that compares sequence | ||
from difflib import get_close_matches | ||
|
||
#json file | ||
dic_data = json.load(open("076 data.json")) | ||
user_word = input("Search for a word: ") | ||
|
||
|
||
def translate(word): | ||
if word.title() in dic_data: | ||
definition = "\n".join(dic_data[word.title()]) | ||
return definition | ||
elif word.upper() in dic_data: | ||
definition = "\n".join(dic_data[word.upper()]) | ||
return definition | ||
elif word.lower() in dic_data: | ||
definition = "\n".join(dic_data[word.lower()]) | ||
return definition | ||
elif len(get_close_matches(word,dic_data.keys())) > 0: | ||
#comparing the word provided with the keywords in json data | ||
close_match = get_close_matches(word,dic_data.keys())[0] | ||
user = input("did you mean %s instead yes or no: " % close_match) | ||
if user == "yes": | ||
return("\n".join(dic_data[close_match])) | ||
elif user == "no": | ||
return("the word does not exist") | ||
else: | ||
return("please check your entry") | ||
else: | ||
return("word not found!!!, please check your word") | ||
|
||
print(translate(user_word)) |