Welcome to this video, so we will head over to part two in collections once we completed the list part,
we would start today starting what our dictionaries and we'll start off the theory part real quick and
held over to the examples.
So dictionaries he's in on all the type of collection python.
What does it mean?
That it's unordered, meaning that once we have a list, for example, we had we had sales.
Right.
We had for example, we had items inside the list like this.
All right.
So we had strings, we had integers and so on.
So for each cell, we had an index.
This was Index Zero and X1 and so on.
But in dictionaries, we do not have index values for ourselves.
We do not have them.
So that's what it means, that it's unordered.
So in other words, we cannot access the information inside the cell by an index, but we can do it
in different ways.
We will see it in a few minutes.
So in dictionary you have items and a dictionary item has a key and value pair.
So the information contained in each cell would have two values, a key and a value.
All right.
Both of them would be in one cell.
So each cell has to contain them both.
Once the key of the dictionary item or dictionary sale, if you like, is the same term, use no one.
We can retrieve the value of it.
So once we know the key, we can retrieve the value that is attached to that key.
In Python, it is expressed as a as a pair key value.
All right.
So, for example, we're talking to our co-worker.
So if we're going to ask him something about this, so are we going to discuss like what's the information
inside the list?
What is the index of the sale that our co-workers is talking about, for example?
But once we discover once we discuss dictionaries, we would ask him, OK, are you talking about the
the key value, like named John or are you talking about the salary 10000?
Like, give me your key and value so I'll know what you are talking about.
OK, so this is like the expression you express it as a pair.
The values in the dictionary can be one of sorry, the values of addiction can be of any types, the
values, but the key must be immutable type.
What does it mean?
Immutable type tasks to be a float integer string or a tuple?
We haven't discussed all yet, but we will in a few videos.
But for now, just remember that the key must be one of those kind and also it must be unique.
So a dictionary cannot have like several cells, like more than one cell with the same key.
It has to have unique keys.
OK, so a dictionary declaration of dictionary is being done like this with curly brackets.
OK, so if you'd like to to declare a dictionary, we do it with curly brackets as opposed to a list
that we did it with square brackets like this.
So that's basically the difference.
So if you see an empty dictionary, you can recognize it by the curly brackets.
All right.
So let's go on.
And if you'd like to insert items into.
Into it will use common between the cells and two dots between the key and the value of each cell,
and what does this mean?
All right, so we have declared the dictionary and now we'd like to put information inside the cells.
So this would be cell number one.
It doesn't have index.
All right.
I'm always focusing on it.
The dictionary does not have index zero.
It does not have it just because.
I want to explain you guys.
What cell am I talking about?
So I'm referring it to the as the first cell.
So this one is the first cell.
It has a key, which is a name.
All right.
The name is a string.
So it's one of the the types that we can use.
And then we have two dots.
And then we have the value, Rachel, so key value there and we have the second sale before it will
put a comma, and then we have here the key, which is a string.
And then we have the value, which is a integer.
OK, so it works like this.
So it's pretty easy.
You see, it's a relative of lists, but it's built off a bit differently because we have a key value,
comma, key value.
And in this we just had on in each cell, we had one information, one value divided with commas.
But here we have a key value in Excel.
All right.
So let's head over to a few simple examples before heading up to the practice part in pie chart.
And the first example will be of how to pull out the value of a cell.
We have two ways.
This is way.
Number one, to pull out cells of value.
We need to mention the key like this.
All right.
So we'll do the print here and then we call out the dictionary and inside square brackets will just
put the key that we want.
Once we print it like this, the output will the output will be the value.
So, again, dictionary and inside the square brackets, we will put the key.
Once we print all this together, we would get the value.
And the second way to extract a value is in the following way.
We can use the dot, get action keyword like this.
So here inside the print, we will call out the dictionary and then use dot get and inside we will mention
the key.
All right.
We will also we will do this again.
We will just call out the dictionary, then dot get and then inside the brackets, the round brackets
will mention the key.
So you can see the difference in the syntax here.
And the first way we call the dictionary and then we have square brackets and we mentioned the key here.
And in the second way, we call out the dictionary, we have the dot get keyword and then we have around
brackets and the key mentions inside and the output will be the value, same as the first one.
So this will complete our basic basic theory regarding dictionaries will hand over to some examples
in polytrauma right away, and that's about Rigi.
So see you in the next video.