Hi, everyone, and welcome.
OK, so let's try to resolve Dictionary's practice assignments and let me just open by charm.
All right.
So once I'm open, let's create a new file.
Call it.
Collection's dictionary practice basics and here is well.
Yeah, so are we good to go?
So, first of all, let's create a dictionary about Alex.
So the dictionary goes as following square brackets and then we have age, Alix's is 32 years old.
And.
Married.
Yes, by the way, we can also put boolean variable here as following, but the assignments said to
say to set a string of yes and last one is kids, which is which has the value of three.
OK, so this was the first thing you needed to do.
Let's print it out.
This is Simon Nimo, number one.
This is Alix's.
Dictionary.
And plus casting and Alex, yep, so it's printed out, see that we're fine, all right.
And so we have printed out the dictionary successfully.
Great.
So let's head over to the next assignment.
And the assignment said that you need to extract.
Values of the dictionary.
Into variables.
Correct.
So let's create reprints, yeah.
It's great, three prints, copy it and then paste and paste and inside those prints, let's state that
we are in assignment number two and we're going to print off page value.
Correct.
So looking at the dictionary.
All right.
So we have three cells here.
This is the first one second and third.
And again, I'm mentioning mentioning that you do not have indexes for those cells.
I'm just counting them for myself and for you guys to understand that we are discussing the same thing.
So we want to print the value, uh, print the value of age.
All right.
And what you were asked to do in this assignment before the prints is to create three variables and
put the values of the dictionary inside those variables.
So we have the H.
Yeah.
And how do we extract a value?
We just mentioned the dictionary, then square brackets and then put the key inside.
Yeah.
So again, we're doing the.
Marriage status.
And then we put the dictionary square brackets.
And put the key inside.
Then we have kids.
Or to be more exact number of kids.
Alex and kids, yeah, so this is what we have learned in the previous video, that this is how you
can assign variables into, uh, like to sign to vet to a variable a, uh, value of a dictionary.
And then what we need to do is print the age of the value.
Print of age value.
Yeah, so we do casting and we put Asian side, Asian side.
All right.
So let's do a quick example for the first one that we will know that we're in the right way.
Right, so we have extracted successfully the aged value.
All right, so first of all, we created a new new variable, which is age, and then we put an equals
mark that this value we want to put inside the age variable.
And what do we have here?
Here we have the dictionary mentioning square brackets, and then inside we put the key and these key
belong value will be extracted by this action.
So basically, it's the same thing as stating H equals 32.
All right.
So this one's output is 32.
It extracts the value of the key that we mentioned.
All right.
Oh, sorry.
All right, so then we have.
We also need to do the print off of the other variables or print off.
Marriage status.
Value, yeah.
SDR, by the way, anybody knows.
Do we need casting here or not?
And I'm asking this because let's have a quick look at the value of the married keys is a string.
So do we need to put casting here?
So let's find out.
Yeah, and in the last one.
We have to, yeah.
Print off.
No.
Yeah, we like this number of kids, yeah, so value.
And then we pulled the string.
This is indeed a, uh, string uh, yeah, sorry, it's an integer.
So this is an integer.
So we definitely need casting because we have a string here.
And if we don't do casting, we have two types of string and is let's print it.
And the question mark, I just want to remind you, want to see what happens here as we didn't do casting.
Yes, so everything worked just fine, and as we just discussed, you do not have to put casting on
marital status, and the reason is because when we pull out the value of this key, which is the value.
Yes.
So it is already a string.
So we don't need to, uh, we don't need to cast a string into a string.
This is this is not logical.
So we don't need to put the casting here.
Yep, so this was the second assignment and the third assignment was.
Bonus one, yeah, and find a way to change.
Dictionary value.
Online, yeah, so we had like a phrase that I asked you to to search by.
So the phrase was Python update value of dictionary.
So just randomly, I'm going to not randomly and just going to speak.
Always the first results here, as long as they're not promoted.
All right.
So let's go to programs, by the way.
I just want to say that all information that we take from that program is dot com is rights reserved
to program is all right.
And now we will see here from the top.
We already discussed it in the previous video that we just need to mention.
The dictionary then used the DOT update action key.
And here, inside, here, inside, you see in the square brackets the phrase other and we not you can't
quite sure understand what is on the other.
So let's go a bit down to see an example.
And isn't the as we saw in the previous video, so we have seen that we have a dictionary, one which
is the best one, and we have the D D one, which is the helper dictionary.
And here we have only one key and one value.
So the key here is to correct and the key here is to as well.
So once we we call out the base dictionary D and we hit the update Key Action Action Key.
Once we put inside the helper dictionary, which is the one, it will take this key and we'll take this
value and it will search where in the base dictionary we have the same key.
OK, so we have here the same key.
So it will replace the value of the helper instead of what we have in the base dictionary.
So this is what we're going to do now.
OK.
So we have assignment number four, which was the following change.
Of age.
Kee.
Change of value, let's say, sell value from 32 to 33, correct?
So what we're going to do now is, first of all, to create an age.
Helper.
Dictionary and we will stay there, the same key that we have in the original dictionary, which is
age, and we will put the the the goal value, which is 33 and right after we will mention the base
dictionary, then dot the action key and inside we will just insert the helper dictionary as following.
So what's going to happen now is once we will apply the update of, uh, upon the dictionary with the
help of the helper dictionary.
So the code will take this key, go to the go to the base dictionary, which is this will find the same
key here and it will replace this value with the new one.
So let's try to print and see that we're correct.
All right, so now we're going to print.
The Alex dictionary one more time and we're expecting to see a 33 value inside the sale of H.
Yes, so this actually happened, we have the value 32 and once we use the Help dictionary to replace
the value, it is now 33.
Great.
All right, let's head over to the following one.
So in the following assignment, we were asked to change the number of kids as Alex has a new kid in
the family.
Joining the family may be, yeah, and what are we going to do as all as well?
A creative kid's helper dictionary.
Yeah, put the key kids inside and put the value for which is what we want to put inside the cell.
Right now we have the value three.
Yeah.
So now it's not kids, it's kids.
Yeah, and now we're just going to do the same thing we did before, I like that update and then put
the Kids Helper dictionary inside.
And again, let's just copy this one.
And based here just before running, I want to do a small thing, I just want to mention here a change
of age and here it is, change of.
Kids, no.
Number of kids, yeah, and let's print it and see what happens.
Oh, no.
Something happened here.
Oh, I see.
I see.
So we have like a Syntex out here.
We need to put this a sign right here.
Let's try to run it.
Yeah.
So the value changed from three to four, as we expected.
Great.
Great guy.
So we're heading in the right way.
Heading in the right way.
Now let's try to do the following thing as we already studied.
And let's just try to print all of the values and keys, uh, of the dictionary.
Yeah, but right here, I just want to maintain order or put the assignment number.
Yeah, so right now we are heading to the sixth one and in the sixth one, we would like to print out
all the keys.
Of Ilex dictionary, and we will do it in the following way.
And we can do it using, first of all, casting and yeah, this is unnecessary and will put Alex here
and then we put that keys.
Yeah, we have seen it in the previous lectures.
And also let's copy this one and why I'll copy.
You know what?
Let's not copy it, because I want you to see maybe you can get some new information while I'm explaining
and showing you the way.
All right.
So the keys and now we need to print out values of Alex Dictionary.
And here we are in assignment number seven, print all values of Ilex Dictionary.
Yeah, it's pretty much the same.
Yeah.
Quite frankly, it's pretty much the same.
So here it's Alex Dot values and printing it out.
Yeah.
Not forgetting the plus here.
Oh OK.
So let's print it.
Yep.
All right, so we have alkies print it out and let's just verify we have age married and kids and we
have old values printed out, which is age 33.
Yes.
And number of kids, which is now four.
And that's about this part.
So I just want to summarize what we have just did in this video.
So we have we have resolved all the practice, basic assignments, and we are now familiar with dictionaries.
We know how to assign and to a certain variable a value of a dictionary.
We know how to change values inside the dictionary using a helper dictionary.
And we also know how to print out the keys and values of a dictionary.
And that's about this topic.
In the next video, we'll start discussing the advanced part of dictionaries there.
You would learn how to do some advanced manipulation on dictionaries as copying a dictionary, deleting
all its values and how how to create a nested dictionary.
And following that, you will also encounter the practice of the advanced part as well.
And this is, quite frankly, a really important topic as dictionaries are used worldwide and in very,
very large scale.
And personally, I also use dictionaries a lot in my automation projects.
So it's a.