Dictionary in Python is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds
key:value pair. Key value is provided in the dictionary to make it more optimized. Each key-value pair in a Dictionary is separated by a colon :, whereas each key is separated by a ‘comma’.
A Dictionary in Python works similar to the Dictionary in a real world. Keys of a Dictionary must be unique and of immutable data type such as Strings, Integers, and tuples, but the key-values can be repeated and be of any type.
Note – To know more about dictionary click here.
- json: It comes built-in with python, so there is no need to install it externally. To know more about JSON click here.
- difflib: This module provides classes and functions for comparing sequences. It also comes built-in with python so there is no need to install it externally.
- Download a
JSONfile containing English dictionary words in a python dictionaries data type format, or arrange the file content in that way.
- Create a folder and add the downloaded .json file and python script in that folder.
- In python editor, import the required modules.
Below is the implementation.
Important, the output should not vary with different cases such as upper case and lower case input of same text should be same i.e rain or Rain or RaIn should produce same output. Also if user mistakes with spelling of word it should return the close words related to the word input or print a user friendly message that word does not exist.
For mixed cases –
If spelling is wrong it gives the word holding closest meaning with word typed by the user as shown. Suppose if the input is “rane” and the user wanter to search “range”, then the output will be as follows.
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.