How to implement Dictionary with Python3? Last Updated : 21 Mar, 2024 Comments Improve Suggest changes 1 Likes Like Report 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. Python # 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 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. Video Demonstration Create Quiz Comment U ujjwal sharma 1 Follow 1 Improve U ujjwal sharma 1 Follow 1 Improve Article Tags : Technical Scripter Python python-string Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like