Introduction:
- A dictionary is one of the most important tool during our study time.
- A good dictionary can help us to understand our subject better and it help us to improve our communication skills.
- It help us to find spelling of a word and to find the synonym or antonym of a word etc.
Python Dictionary:
- A Dictionary in Python works similar to the Dictionary in a real world.
- It is in the form of Key - Value pair.
- The Keys of dictionary must be unique and values can be duplicated.
Modules Needed:
- json - it comes built in with python, so there is no need to install it externally.
Steps:
- Download the JSON file containing English dictionary words from our github site.
- Create a folder and add the downloaded .json file and the python source code script in the folder
- Then open that python source code script in the python editor and then run it and then you will get the output.
source code:
import json
data = json.load(open("dictionary.json"))
decision = True
def get_meaning(word):
if word in data:
return "The Meaning for the word '%s' is:" %word , data[word]
while decision == True:
word = input("Enter the word: ").lower()
meaning = get_meaning(word)
if not meaning == None:
print(*meaning)
else:
print("Sorry!!! The word '%s' doesn't exit. Please check the word one more time." % word)
yes_or_no = input("Do you want to continue Y/N: ").lower()
if yes_or_no in ['yes','y']:
decision = True
else:
print("☺☺ Thank You ☺☺")
decision = False
Output:
- The Full Source Code is available on our github site.
Click here -- github
***********************************************************************************
0 Comments