We can add extra dimensions to lists and dictionaries because a list can contain a list and a dictionary
can contain a dictionary.
So I've created this list and it has the elements one, two, three, four, five, six, seven, eight,
nine.
But those elements are lists themselves, so they're in groups of three.
So this is the first element of the outside list.
This is the second and this is the third.
So if we index this list now and we go for the first element, the first element is one, two, three.
The second element is four, five, six.
And you've guessed it.
The third element is seven, eight, nine.
Now, if we wanted to access this five, for example, we would do it like this.
My list one or access the index one item in the outside list, and then we need to put another one to
index the middle item in this list that's inside the outer list.
And if we do that, we return five.
So let's now look at a more interesting example.
With a dictionary, we have this country's variable, which I have now updated.
And instead of just having key value pair being a country and a capital, it now has a key value pair
where the value of the key is itself a dictionary.
So the first key is France.
And the value of that key is a dictionary, which itself has key value pairs.
In this case, it's capital, Paris, language, French.
And we've got that for France, Spain, the UK.
So what happens now if we try to access the key France?
Let me just copy this and I'll put it in the console and we'll see what happens when we run it.
And we get capital Paris, language, French.
So we've returned a dictionary because this key is associated with this value and this value is a dictionary.
So let's try printing over the key value pairs like we did before and see what we get.
So now we get the key value pairs, but those key value pairs are a key and another dictionary.
So let's iterate again.
But this time we're going to try to access information in that nested dictionary.
So for key value in countries items.
So we're just iterating over countries items, the countries key value pairs as before we using this
F string and we're saying value capital.
So we're accessing this nested dictionary, this dictionary inside the dictionary.
And then we are using its key, in this case the capital, in order to access this value.
So we're using the key value pairs.
This is the key.
This is the value.
As we iterate over those, we are then asking for the values key because the value is itself now a dictionary
to return this value.
And we're saying that in this case, on the first iteration, Paris is the capital of key, which is
France.
We're using that.
They speak value.
Now, value is a value, but it is also a dictionary.
And we're using the key language to return the value here, which is French.
So let's now execute that and see what we get.
So we have Paris is the capital of France.
They speak French.
Madrid is the capital of Spain.
They speak Spanish.
London is the capital of the U.K. and so on and so forth.
So you can see how powerful and useful dictionaries are just in this small example.
And they're very efficient ways of storing data.
And they can be used to be converted into something called a data frame, which we will touch on later
on in the course, which are very powerful when it comes to manipulating and analyzing data.
So that's something that you really should spend some time trying to understand and getting to know.