Created
December 2, 2019 14:33
-
-
Save aydinnyunus/00d0d3586ce84c14f883404ae4a25cc0 to your computer and use it in GitHub Desktop.
English Dictionary on Python
This file contains hidden or 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
Dataset : https://raw.githubusercontent.com/aydinnyunus/Dictionary/master/data.json |
This file contains hidden or 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
import json | |
from difflib import get_close_matches | |
data = json.load(open("data.json")) | |
def translate(word): | |
word = word.lower() | |
if word in data: | |
return data[word] | |
elif word.title() in data: | |
return data[word.title()] | |
elif word.upper() in data: | |
return data[word.upper()] | |
elif len(get_close_matches(word , data.keys())) > 0 : | |
print("did you mean %s instead" %get_close_matches(word, data.keys())[0]) | |
decide = input("press y for yes or n for no") | |
if decide == "y": | |
return data[get_close_matches(word , data.keys())[0]] | |
elif decide == "n": | |
return("pugger your paw steps on wrong keys ") | |
else: | |
return("You have entered wrong input please enter just y or n") | |
else: | |
print("pugger your paw steps on wrong keys") | |
word = input("Enter the word you want to search\n") | |
output = translate(word) | |
if type(output) == list: | |
for item in output: | |
print(item) | |
else: | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment