Skip to content

Instantly share code, notes, and snippets.

@Dhrumilcse
Created November 18, 2018 07:40
Show Gist options
  • Save Dhrumilcse/021fe3cbdef469ff75716ad7329734ee to your computer and use it in GitHub Desktop.
Save Dhrumilcse/021fe3cbdef469ff75716ad7329734ee to your computer and use it in GitHub Desktop.
Dictionary Part 2
#Import library
import json
#Loading the json data as python dictionary
#Try typing "type(data)" in terminal after executing first two line of this snippet
data = json.load(open("dictionary.json"))
#Function for retriving definition
def retrive_definition(word):
#Check for non existing words
if word in data:
return data[word]
else:
return ("The word doesn't exist, please double check it.")
#Input from user
word_user = input("Enter a word: ")
#Retrive the definition using function and print the result
print(retrive_definition(word_user))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment