This program uses python’s container called dictionary (in dictionary a key is associated with some information). This program will take a word as input and returns the meaning of that word.
Python3 should be installed in your system. If it not installed, install it from this link. Always try to install the latest version.
I made a text file in which word and its meaning is stored in python’s dictionary format
Example :
data = {"geek" : "engage in or discuss computer-related tasks
obsessively or with great attention to technical detail."}
Here if we call “geek” from data then this will return its meaning “engage in or discuss computer-related tasks obsessively or with great attention to technical detail.”.
This python program allow you to fetch the data of this text file and give the meaning.
# Python3 Code for implementing # dictionary # importing json library import json # importing get_close_matches function from difflib library from difflib import get_close_matches # loading data data = json.load(open("data.txt")) # defining function meaning def meaning(w): # converting all the letters of "w" to lower case w = w.lower() # checking if "w" is in data if w in data: return data[w] # if word is not in data then get close match of the word elif len(get_close_matches(w, data.keys())) > 0: # asking user for his feedback # get_close_matches returns a list of the best # “good enough” matches choosing first close # match "get_close_matches(w, data.keys())[0]" yn = input("Did you mean % s instead? Enter Y if yes, or N if no: " % get_close_matches(w, data.keys())[0]) if yn == "Y": return data[get_close_matches(w, data.keys())[0]] elif yn == "N": return "The word doesn't exist in our data." else: return "We didn't understand your entry." else: return "The word doesn't exist in our data." # asking word from user to get the meaning word = input("Enter word: ") # storing return value in "output" output = meaning(word) # if output type is list then print all element of the list if type(output) == list: for item in output: print(item) # if output type is not "list" then print output only else: print(output) |
How to run?
- Download this data file and save it in the same folder where your python code file is saved.
- Make sure that both the file(data file and the code file) are in same folder.

- Open command prompt in that folder to do so press shift then right click in mouse.
- Run the python code using cmd(command prompt).
- Input the word whose meaning is to be searched.
- Output will be your result.
- Python3 Intermediate Level Topics
- Python3 for GUI application | An Overview
- How to write Comments in Python3?
- Python2 vs Python3 | Syntax and performance Comparison
- Automate the Conversion from Python2 to Python3
- Convert String to Double in Python3
- Introduction to Python3
- Python3 - if , if..else, Nested if, if-elif statements
- Why PyPy3 is preffered over Python3?
- Different Input and Output Techniques in Python3
- New '=' Operator in Python3.8 f-string
- Positional-only Parameter in Python3.8
- Itertools in Python3
- Setting python3 as Default in Linux
- How to print spaces in Python3?
- How to use Variables in Python3?
- Guide to install TuriCreate in Python3.x
- What is Three dots(...) or Ellipsis in Python3
- How to create an instance of a Metaclass that run on both Python2 and Python3?
- Flipping Tiles (memory game) using Python3
Video Demonstration
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai

