In this lecture, I'm going to show you how to use dictionaries in Python, the dictionary is a data
structure that allows you to store key and value pairs as long as the case is neat and there's no limit
to how many of those keys and value pairs you can store.
Going to give you a simple example to begin with.
So let's say that you're building an application that keeps track of the specifications of your E.S.P
32.
You could use a dictionary like this one here.
There are about Paiste girl that contains information about the E.S.P 32 information about the manufacturer,
the type of device it is that should be used using and so on.
So as you can see, I've got multiple keys like manufacturer with.
The value for that key, so there's another key here type and its value is microcontroller is a key
city, you and the value your piece of string in this case, of course, you can have values that are
numerical or a booleans, et cetera.
If you check out the contents of this dictionary, just type in its name, you'll see that it starts
with a curly bracket, finishes with a curly bracket, and then you've got the key and the values in
between four.
Click on the dictionary.
It appears as well in the object, Inspector.
So you can see it in a table format.
Now you can do a few operations on a dictionary once you have it.
For example, a common one is to use the list command and pass in the name of the dictionary.
And what this is going to do is to bring back or give you create a list that contains the individual
keys that are part of this dictionary.
This you can see the square brackets.
This is a list.
You can use it in a iterator like a folded, for example, so that you can iterate through all of the
keys of the dictionary and perhaps print out the values for each key or do some other kind of text processing.
Of course, you can extract the individual values for each given key.
So, for example, if you wanted to print out the RAND value or the value stored in the RAND key of
the dictionary, then you can use the square brackets and then in between the square brackets, type
in the name of the key that you want to get the value of it into.
And you will give you that specific value, which is this one right here.
Dictionaries are mutable, which means that you can make changes to the values of existing keys or you
can add new key and value pairs.
So, for example, I can make a small change to the brand that you can see here.
I'm making reference to the particular key that I want to change the value of the material change to
the value stored there originally.
That's five hundred and twelve kilobytes of static ram.
Let's make that five twenty one for the sake of the argument hit enter.
So now we've got a new value for that Calixto against that key.
So in other words, dictionaries are mutable.
You can also use.
A Syntex like this, in order to check that a particular case exists inside a dictionary so you can
say the name of the key and check using the key word if it exists inside the dictionary.
In this case, it does exist.
If I search for something that does not exist, then.
You'll get folks, it's expected.
Now, the easiest way, as I showed you the beginning, the easiest way to create a new dictionary is
to use the curly brackets and then the key values inside the curly brackets.
But there's also a constructor that you can use, which can be an example here.
Expect this to this constructor uses the dictionary with Dict Keywood, and then you've got the parentheses
for the keyword and for the square brackets open and and then inside parentheses, you list the key
value pairs like that.
And that has the same result.
Eventually, he has a new dictionary that looks like this, just like the one that we created up there
using two different ways to achieve the same result.
And that's how you use dictionaries completely.