This video, we will build an English dictionary.
This is a program which gets from the user a word in English and in three turns the definition of that
word in English.
Now we will be using Jason -.So for this.
So Jason, he said, other formats and it's similar to a Python dictionary.
So in this video, you learn how to pass that these data and extract information from those data.
So the idea is that the data said the dictionary itself is stored in these JSON delta and this is a
file.
You can find this at the end of the lecture resources.
So you need to place it in your project directory and they look like this.
Be careful not to change anything here.
Otherwise, the format may be corrupted and Python will not recognize that.
So you will get some errors later.
What we have here is a big dictionary, and this dictionary is made of keys and values.
So that's the value of the first key of the other pair key and value up to here.
So the key is a word.
The value is a list which may contain one or more definitions for that two words.
So these are adjacent.
And as I say, that these are similar to Python.
Now let's go to Python painful JSON, which is a Python standard library to parse Jason data.
And then the next thing we should do is apply that JSON that loads method and the load method expects
a file object as inputs so we can create a file object in here file equal to open data.
Jason So that will create a file in read mode and we provide that file in here.
And if you print that up.
You're going to get all those that are printed out in your terminal.
So it's the same delta as we saw in here.
And it is a Python dictionary.
So if you print out the type stop print, you're going to see class DeCoutere.
That means you can now access any of the keys, such as islands.
So if you access the key islands, you get a list.
So this list happens to have one and two items.
So there are two definitions for the word islands.
So I would like to make this more robust and create a function.
So define, define this will get a word as input if the words in Delta eight to the return.
The definition of that word, sorry.
Words as a variable.
So that our words will be like Delta Island, for example, Delta Sun, etc. So this will happen if
the world is in that dictionary, otherwise else we want to return none.
But are you going to amidst this expression?
Because if the if condition is not ever alluded to by default, this function will return none.
So there is no need to return, not explicitly.
So, no, we can see we can get the words from the user base into a word
and then we get the definition from the defined function.
But passing that word?
So word goes in here as an input.
To the function, call and print out the definition, and so, yeah, that looks fine.
I'll remove this print statement up here.
Remove that and run.
So police enter a woods island and we get this list.
What if we put a word which doesn't exist?
Such as Iceland with the set, so we get none.
If you want to improve this article, you could simply do here if definition print.
Definition else.
Brent Woods was not fond and run.
And the word ises and word was not found is written as.
Another improvement of life to make here is that, you know, if you answer the correct words such as
Ireland boss, you enter a capital I.
And you press, enter this race.
And it was not fun because Ireland's here is in lowercase letters.
So Ireland with a capital I and Ireland with a low case, I are not the same.
So you want to change that.
You want to see if world is lower, so you get the words of the user and you convert it into lowercase.
So what you check in the delta is the lowercase version of that's user input.
So if you were on that answer, I along with uppercase, I enter, Oh, we got an error in line eight.
Obviously, we need to cover that in here, too.
So instead of doing that, just say words is equal to words, not lower.
So this variable now is converted into a lowercase for all the occurrences of the words variable inside
this function.
So run that again, try again, islands.
And this time we get this list of definitions.
Would you like to improve the ultimate even further by removing this brackets?
Well, for that, instead of printing either definition, which is a list you want to iterate and see
the list for item in definition.
So definition is the least.
We trade over the items and we print out each item in here run.
And so now we have no brackets, so every line is printed out as an individual sentence.
And that's concludes this video.
Thank you.
I'll see you later.