Hello, everyone. And welcome to intro the python here on Cyber Eri on demand I am your instructor, Joe Perry and you're watching less and nine, the final lesson of this class in which we're going to be doing a deep dive on python dictionaries. And just like with the last lesson, we only really have two objectives here. We're gonna learn the key dictionary methods.
We're gonna learn to make use of dictionary. So we talked about dictionaries very briefly and module one,
we haven't really dug into them the way they deserve you dug into because dictionaries are incredible, you could do so much with them. They're just these ridiculously useful tools. So we're going to really dig into those. We're gonna spend some time on them here in this lesson. So first, just like we did with lists we're gonna create our first dictionary, which we're gonna call dicked one
actually do underscore with the word one,
and we're just going to assign a couple of simple key value pairs.
So here, remember that as we do with lists we can address inside of dictionaries,
But instead of using indexes, we use the key
and note that you can't
reverse that. You can't use the value to find the kid has to be the key to find about you. Anytime you give a dictionary a bad key, it'll spit out a key error, and it's just gonna tell you whatever he used was not valid.
So let's look at just like we did with lists and strings and numbers. Let's do a door against that dictionary
and see what things are available. Now it's just it's a shorter list. There were for strings because you into a crazy amount with strength.
But here you see, we've got clear copy from keys, get items, keys, pop, pop items, set default update and value
the ones that I really want to look at. First of all,
let's look at dicked one dot keys.
You can see this is a built in method,
so that means that it's a function
so we can address it
and you see it's going to spit out
this list right here of 13 and five.
And *** Keys is basically just Ah,
I'm not gonna dig too far into exactly what that means, but essentially, it's it's an honorable It's something that you can address. So, for example, you could do something like four I in dicked one
And what this is going to do is it's gonna get back that irritable, essentially list of keys, and it's gonna go through Key bikey Pikey pikey, pikey printing The values associate it here. You can see that we print 24 and six.
So that's one of the really useful things you can do it. Dictionary says get all of the keys back and print all of the values
if we wanted to. And this is a slightly advanced use of four loops. But I'll show you for key for K V in dicked one
actually do that slightly differently for K in dicked one dot keys
So that's a slightly complex function that we just wrote there. What we're doing is we have these to remember our brackets from our discussion of strings were using format. We're saying the first item to insert is the key. The second item to insert is the value that we find by looking it up in our dictionary
and you see here that will print 123456 So that's an easy way to find all of the associated keys and values in a dictionary.
Now let's look back at our list of functions for
and we see that we have talked about keys. We also have pop here, and pop is a little bit different in a dictionary than it is in a list. And to see that, we're gonna go ahead and we're gonna do help.
And you see that you have the argument here of K and ah, optional argument of D. We're not gonna dress right now
and that it's going to return V so it removes the specified key the same way we did with pop and lists when instead of giving you back, that key gives you back the corresponding value.
and we'll give it the key of five.
So it printed six. And now, if we look at the dictionary itself, we see that it no longer contains that key value pair, so that's a little bit different because you're actually popping with a specific argument telling it which key to take. It's not just taking the last item is taking a specific key, and it's removing that key and the value from your from your dictionary and its printing or returning back that value.
So that's the general concept dictionaries. You really the uses you're going to get out of. These are just
There's so many potential use cases for dictionaries. You can associate data with them. You can get access to all of the functions, all the methodologies inside of them
which is gonna be coming up right after the summary and review video. You get a chance to really play around with dictionaries and see all the different uses of them. But I wanted to show you just again how to create them, how to address them, how to find the methods of them and just they're just these remarkable tools that I absolutely love. I get really, really excited talking about them
in this video. Like you said, we talked about the key dictionary methods and then we discussed sort of the different uses of dictionaries and in your supplemental materials. You'll get to do a lot more of that.
So if you finish this video, you're about ready to do our somewhere in view and then our final lab and our final assessment. And I just want to thank you for being here with me through all of this, and I'll get a little bit sappy about it in our next video. But just thank you so very much for watching this. I as always, have been your instructor, Joe Perry. And you have been watching you have completed your last lesson off
intro to Python here on Cyber Eri