Master Python through building real-world applications (Part 1)

Get close matches function takes the word the user has entered as the first parameter and our whole data set to match against that word..Here, the key is the words in our data and value is their definition, as we learned it earlier..The [0] in return statement indicates the first close match of all matches.Step 5 — Did you mean this instead?Step 5 — Did you mean this instead? (Output)Yes, yes, that’s what I meant..So, what now?.you can’t just leave that with a question..If that’s what user meant, you must retrieve the definition of that word..That’s what we are going to do in the next step.Step 6 — Retrieving the definitionOne more input from the user and one more layer of if-else and there it is..The definition of the suggested word.Step 6 — Retrieving the definitionStep 6 — Retrieving the definition (Output)Step 7 — The Icing on the cakeSure it gets us the definition of rain, but there are square braces and all around it, doesn’t look good huh?.Let’s remove them and give it a more cleaner look..The word rain has more than one definition, did you notice?.There are several words with more than one definition, so we will iterate through the output of those words having more than one definition and simply print out the ones with a single definition.Step 7 — The Icing on the cakeStep 7 — The Icing on the cake (Output)Looks much better, isn’t it?.Down below I am attaching the entire code for your reference and feel free to modify and upgrade the code as you like.The codeAn Interactive DictionaryEnd notesYou learn a lot while you are involved in it.. More details

Leave a Reply