Hello, everybody, so we now start discussing dictionaries and this will be the advanced part in the
previous videos that we got familiar with dictionaries, and now we'll learn some more cool manipulations.
We can apply on it and we will learn how to create a nested dictionary, will learn how to remove cells
out of the dictionary, how to make a duplicate and many more cool stuff.
So first one is line is how can we create a nested a dictionary with nested entities and what is nested
for that?
Let me open the explorer and what we can see here.
For example, we have the C drive.
OK, so there is a small arrow here and once I click it, I can see what's inside the C drive so I can
address C as a parent can tie it is the parent of follower of the city of BitBucket and so on.
C is the parent and these are the child entities inside it.
So this would, this would be called a child and this is a parent.
And if we click on audacity, so we have additional nested folders inside it.
So off halp folder audacity is the parent, while help is the child of audacity.
So this is this what nested means nested means you have inside the parent while you have items inside
it.
OK, so in previous lectures, we studied how to create a key value dictionary, which was simple,
we just initiated we just declared a dictionary and then inside we put key value, key value items.
Now let's try to learn how to create a nested dictionary.
The dictionary will contain two or more layers on it, on each key.
In other words, you can see here a nested dictionary, and it contains the following we have here.
This is.
A parent cell, and this is also a parent cell, because these are the like muscle cells.
All right.
This is the outside layer of dictionary, same as we have here, key value.
So in this occasion, we have key.
Value.
Kee.
Value, these are this is a parent cell and this is also a parent cell.
OK, so we see that this day and we are kids of parents cells.
And while David and Lisa are keys of an inner layer, which is the child cells.
So let's see, what do I mean here?
All right.
So, mijo.
All right.
Joe is a Web automation developer, and this dictionary is about Joe.
So we can see here.
And Joe, we declared the dictionary and here we have the following.
We have the key age and we have the value.
Thirty five.
And then we have a comma separator between two parent cells.
This is the first cell what marked in green and this is the second cell.
So we have here a key age thirty five.
And here we have also a key, which is kids.
And the value is what comes after the kids.
All of this David boy, Lisa girl, all that part is one one big value that is attached to the kids
key.
OK, and once looking inside the kids value, you can see there additional nested cells.
So inside that you can see David, which is a key and the value is a boy.
And because the key of the both child cells, the key of them are kids.
So here we are going to have some information about kids, obviously.
So we have David, which is a boy, and this is child's cell one.
It is nested.
And we also have Lisa, which is a girl, and this is child cell two, which is also nested.
They are both nested inside kids.
So this is quite simple.
If you get the hang of the rules here and it's pretty much the same, only you will drill down inside
the cells.
All right.
So this is a good example to understand from for for the practice and follow following topics.
OK, so it's pretty much the same.
There's nothing new here.
Just the difference is that until now we knew that we have QI, which is one certain string or a number,
and we have a value, which is also a string number or boolean.
And here in the kids, our value is not only one type of input, it has nested for inputs.
So the value now has nested cells.
OK, so coming to the next topic, which is related to the what we just learn how to extract a value
bickie out of a nested dictionary.
So we have learned in previous lectures that if you want to extract a value, for example, we have
this dictionary once.
We want to extract the H the H sale value.
So I'll just mention the dictionary, then square brackets and put the key inside.
And then once we apply it and print it out, the output is obviously going to be thirty two.
OK, this one we have already learned.
And now let's see how can we do it with nested.
OK, so here we have an example for nested dictionary.
All right.
And let's see how it works with Nesto Dictionary, and once we need to extract the value out of a nested
dictionary, we do it in the same way.
Yeah, so we do it in the same way and the way to do it, if you want to extract a dictionary next,
it says we should use their key, which is kids.
Yeah.
So if we have a dictionary here.
And as we did here before, we wanted to extract the value of age, meaning 32, we just mentioned the
dictionary have put the key inside square brackets.
So here we are going to do just the same thing.
We're just going to do Joey and then kids.
And once we apply that, we can extract the values which are inside the value cell and we can't even
go further and.
Doing advanced example.
Which will be the following.
So what if.
We want to just want to lose the mark yellow marker, so if we would like to extract.
The value.
Like the gender.
Of David, how can we do it?
OK, so the way to do it is, first of all, to extract the kids and then from inside the kids, we
need to extract David, which is also the key.
Correct.
So once we apply this, it's like double extraction, we will get the output of.
Boy, OK, so this is the way to do it if you want to extract the right part here right part, which
is the value you just mentioned the kids key, if you want to extract the value of the inner cell,
you mentioned this key.
Once you mentioned this key, this is for your disposal and then you want to extract the boy.
So you mentioned David, which is this key and then you will extract the boy value.
OK, all right.
So now let's see, how can we create a dictionary, which is a copy of an existing dictionary?
Sometimes we want to make duplicate of our existing dictionary and we can achieve it by using the copy
action.
All right.
So in a few seconds, we'll see how to do it.
It's pretty simple.
OK, you just declare a new dictionary, then you do equals and then you mention the old dictionary
and use the DOT copy action.
So now once we try to print.
Joe, a new dictionary, we will see a printout of exactly what we have in the original dictionary.
So this is how you duplicate the dictionary.
And now, last but not least, basically it's not last.
All right.
So we have we we want now to delete a complete cell.
We already encountered the pop action key in this.
So we know how to delete cells in this.
But let's see if it's the same in dictionaries.
So we use pop action, same words do the lists.
This will delete both key and value of the cell.
This means that if we do the following thing, we address this dictionary and we use pop and put inside.
OK, we put inside the key item inside the box.
So once we apply this meaning, we want to remove this cell.
Once we print Alex afterwards, after using Pop, we'll just lose the age and the 32 values which are
key and value connected AM, and this way we will just delete them out of the dictionary.
And now let's see, how can we add a new cell, for example?
We would like to add a new cell to the dictionary.
We have again, we have this one.
We have Alex Dictionary.
And the way that we can add additional cell here at the end is the following.
We just mentioned the dictionary right after in square brackets, we put the Newquay that we want to
insert and then we do equals and mention the value.
All right.
So in our in our case, we'll just do this, Alex, then square brackets and then I have I want to add
an apartment number five to the list, to the dictionary.
So I apply here the key apartment number.
And here I supply the value.
And then after we print the dictionary, we will have this part, which is the old part which was existing
before.
And we will also additionally have the new part, which is the key that we answered and the value easy.
Right.
There's nothing too complicated here.
Once you get the things, once you get down to the core of it, nothing is too complicated.
And finally, last but not least, how can we remove all elements out of the dictionary?
Meaning we want to remove everything to do a clear cache, to do a scratch everything out of the dictionary.
So this one is very simple.
We just use the clear action key and then once we use the clear, we try to print the dictionary and
we get nothing.
We just get clean, curly brackets and that's it.
There's nothing there.
All right.
So this was the advanced part of dictionary.
I hoped you liked it.
We learned a lot of things here, and obviously this is the main part of it.
And try to reverse this lecture.
If you didn't get all the parts, it's sometimes good to hear the same mixture several times.
And this is about it for that part.
All right.
So in the following video, you will get practice regarding this material and afterwards also a resolution
for it.
OK, then that's about it.
Bye bye.
See you in the next lecture.