Hi, everybody, and welcome.
So now I see completed variables lists and completed the first part of dictionary basics, we'll see
much more examples regarding dictionaries by chance and things are going to be a little bit more complicated.
But as long as you listen to my instructions, everything is going to be just fine.
All right, then.
Let's begin.
So, first of all, let's create a new file in our project and call it.
Collection's dictionary basics and let's leave a nice comment for the future for ourselves.
Yep, so first of all, I want to just mention that this video would be a freestyle video that I will
show you cool.
Still cool stuff and cool tricks that you can use and dictionaries.
And part of this video, the first part will be based on the previous lecture and we'll just going to
see it inside our coat.
So first of all, let's create a new dictionary and not create the.
But create.
Yeah.
And let's give it a name dictionary example.
Um, or let's give it more indicative name like employee.
A new employee.
Yeah.
New employee like that.
And let's start putting values inside.
Let's give the first.
So the key uh first name and our employee is David.
David has a salary of.
Ten thousand dollars, and he works in a small company that some of you might know called Google.
All right.
So first of all, let us just do a simple thing.
Let's just print the dictionary and see that we're OK.
Plus, casting and new employee.
Yeah, so it's runit.
See that everything's fine.
Yeah, so we have the dictionary right here great, so we can continue.
So as you recall in previous videos, in previous video, we found out that we can extract cells with
two ways, so let's try to use it.
So get cell.
Value.
First, we saw the first way was mentioned the dictionary, which is new employee, and then use square
brackets and let's extract the first name.
All right, so you put the key that you want.
It's value being extracted.
So we are putting this key and we want to extract the name.
So it's surrounded with a print action and the comment.
Yeah, get the value of first name key and let's put casting here.
Yeah.
And let's hope, hope for the best.
Whoo!
Yeah, so we got the name David and we have extracted the value of first name, so we have also a second
way.
So get cell value.
Second way, anybody remember how do we do it?
I recommend you to check the attached file to the previous video, the PDF attachment file.
All right, so how do we do it?
We we call out the dictionary and then we put that get by the way, notice that we have many options
here and we will get back to them in a moment.
So new employee then get and then here we want to extract salary, just a different one.
Let's do a print and then get value off salary key.
Yeah, so we want to extract the salary and we'll put here casting of string.
OK, so let's print it.
We're expecting the value ten thousand to be printed out.
OK, so there we see it.
Great.
So now we have basically two actions that we can use to extract values out of the cell.
And the next thing that I want to do before before heading to the next to the next bar, I just want
to mention a small thing.
A pie chart is all is not all is not just a development environment.
It's also a learning tool if you know how to use it.
OK, so Pyfrom can give you hints of what options can you use in your code and then really recommend
you to do it.
And the only way to do it is by experimenting.
I personally studied a lot using by Charm's hints and we will see how to do it right now.
So first of all, let's call out the dictionary.
And just a few moments ago, when we did not get we seen here a pop up with lots of options.
So all of these options are very valuable to use upon dictionaries.
So why not using them?
So let's try to use them.
So first of all, we're already familiar with this guy with Pop.
We apply it on lists in previous lectures and we in previous lectures when we use lists, we mentioned
we mentioned here the index number.
But as you recall in the previous video I mentioned that dictionary is an unordered a collection.
So we can't apply index Salleh index here.
This would be wrong.
So what we want to do is to mention the key here and just going to do an experiment and put Sellery
here.
By the way, it doesn't matter if you put Equitation double quotation marks or just a single one like
this, it's the same effect just as long as you don't do one of each kind like this, OK, as long of
as long as both of them from the same kind, double or single.
This is OK to pie chart.
So let's put celery here and then let's try to print the new employee dictionary.
And what I'm expecting to see is when once we're using Pop that we would like to the cell to be removed
and we're expecting for all this to be removed.
The key and the value.
OK, so let's try to print it and see what happens.
Yes.
So as expected, the salary cell was completely deleted out of the list.
Out of the dictionary.
It's not here anymore.
OK, so I just had the comments removed.
Dictionary cell by using pop.
And I'm just going to copy this one.
And.
Police youth here inside quotation marks.
Yes.
So this is it, this is what we have learned now that if we use dot pop, we can remove the cell from
the dictionary.
So it only by experimenting because I see the dictionary dot and I saw in the pop up lots of options
over there.
And why not using them?
Why not trying to use them?
And we can study lots of things by using and try and experimenting new things and I.
Right.
So it's a good it's highly recommended by me to do experiments and it can be very useful to study new
things like that.
So let's try to do a different thing.
Let's call out the dictionary.
And why do you think if I use the value or Keyes action, what will happen like that?
So can I maybe guess what will happen?
So is it logical to say that if I printed it would give me all of the keys of the dictionary?
Am I right?
That's very logical.
So let's try to print it and see what happens first and then we'll put a comment afterwards.
So it's printed.
So indeed, as we just said, we will see all the keys printed out.
OK, so print out all keys of the dictionary.
So this is also a very powerful tool that we can extract all of the keys at once.
Yes, so casting.
Yeah, so that's great, and I'm just going to copy this one, because we have keys and we also have
values, and it's really logical to understand that both of them doing the extraction in the same way,
one on keys and one on values.
So I'm just going to change the word values in all relevant places and try to print it.
Yeah, and here we want to place values as such and try to print it, and also here we have printed
out we have extracted all values out of the dictionary.
All right.
So this was very, very useful to just experiment.
Just experiment.
Do not be afraid to get some errors.
The worst case scenario is you get an error and the best case scenario that you learn new things.
And once you learn a new thing, you can use it forever.
It gets gets in, your DNA gets in your mind, and then it's yours forever and you can use it for the
wrong according to your requirements.
So now, guys, I'm going to head over to the last part of the theory example part.
And I'm just going to combine two topics together.
As you recall, in our first lessons, we have studied what our variables.
So I'm going to use variables and dictionaries together.
And basically what I'm going to do is instead of hard coding the values and the keys inside the dictionary,
I'm going to create a variable and place a variable instead, a hard coded value as such.
Just put the variable inside and then I'll try to print it and see the value of the dictionary prints,
the variable that I've put inside.
So I'm just going to use a variable.
And place it inside the dictionary.
A dictionary cell.
OK, so my variable will be job title and output developer here.
And and I'm going to create a new.
Dictionary.
And port.
Like job.
Title.
Yeah, and put job title, you know what, let's give it a different name, job title valued small,
correct, more indicative.
So that's just copy it and place it here.
OK, and now let's just print it, print the new.
Dictionary plus casting and new dictionary.
All right, so what I'm expecting to get is to print out the list, but as you can recall, as you can
see, I'm not using a hard coded values here.
I'm just using a variable and placing it inside a dictionary.
So it's printed.
There you have it.
We don't see anything.
All right.
So let's see what's wrong.
Oh, obviously, we printed the old dictionary.
New dictionary.
Yep, so this work, yep, so we can see the new dictionary printed out and you can see how topics are
gathering together.
So now you can also use dictionaries together with variables.
And all the same, you can also apply variables inside lists as well.
So, like both topics are mixed, and as long as we go forward, they're all topics will be combined
together and we can invent and we can create cool stuff using all the tools together.
So this will be the final part of the theory basics regarding dictionaries.
I will see you in the next video and we will practice at the dictionaries and that's about it.
All right.
Bye bye.