Skip to content

Instantly share code, notes, and snippets.

@aydinnyunus
Created December 2, 2019 14:33
Show Gist options
  • Save aydinnyunus/00d0d3586ce84c14f883404ae4a25cc0 to your computer and use it in GitHub Desktop.
Save aydinnyunus/00d0d3586ce84c14f883404ae4a25cc0 to your computer and use it in GitHub Desktop.
English Dictionary on Python
Dataset : https://raw.githubusercontent.com/aydinnyunus/Dictionary/master/data.json
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