Module used:
In this script, we will use the JSON module because we will use a JSON file and loading requires the JSON module. We will use difflib module.
What is JSON?
JSON (JavaScript Object Notation) is an inbuilt python library which provides us various functions to read and write the file with .json extension and it usually deals with the file which looks like a python dictionary.
What is difflib?
A python inbuilt module that provides us with various functions to compare various sequences in python, from this module we will use the get_close_matches() function which gives us the list of words which are very close to the user's word.
Note: There is a JSON file that you have to download which contains all the words with their meaning but as there are too many words we are not able to access them that's why we will make this script.
Creating An English Dictionary In Python
First of all, we will take the users input as now the user can give us input in any way (.lower manner, .upper manner, .title manner) so we have to check for every condition, sometimes what happens the user's input didn't get matched with the words in the JSON file. In this case, we will provide similar words for the user's input with the help of get_close_matches() function.
Note: The JSON file must be in the same directory otherwise you have to specify the path of the file.
Program:
Output:
The link to Download the JSON dictionary File: https://github.com/abhinav0606/dictionary.py/blob/master/dict.json
need an explanation for this answer? contact us directly to get an explanation for this answer