Time
2 hours 57 minutes
Difficulty
Beginner
CEU/CPE
3

Video Transcription

00:00
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.
00:19
We're gonna learn to make use of dictionary. So we talked about dictionaries very briefly and module one,
00:24
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
00:43
actually do underscore with the word one,
00:45
and we're just going to assign a couple of simple key value pairs.
00:55
So here, remember that as we do with lists we can address inside of dictionaries,
00:59
But instead of using indexes, we use the key
01:03
and note that you can't
01:06
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.
01:17
So let's look at just like we did with lists and strings and numbers. Let's do a door against that dictionary
01:23
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.
01:30
But here you see, we've got clear copy from keys, get items, keys, pop, pop items, set default update and value
01:34
the ones that I really want to look at. First of all,
01:38
let's look at dicked one dot keys.
01:41
You can see this is a built in method,
01:42
so that means that it's a function
01:46
so we can address it
01:48
and you see it's going to spit out
01:49
this list right here of 13 and five.
01:53
And *** Keys is basically just Ah,
01:55
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
02:05
dot keys
02:07
Prince.
02:12
Bye.
02:13
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.
02:25
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
02:31
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
02:39
dot keys
02:44
actually do that slightly differently for K in dicked one dot keys
02:52
prints
02:58
for me.
02:59
Okay,
03:00
Nicked one.
03:07
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
03:23
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.
03:30
Now let's look back at our list of functions for
03:35
addict one,
03:36
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.
03:49
And you see that you have the argument here of K and ah, optional argument of D. We're not gonna dress right now
03:55
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.
04:08
So I'll show you
04:15
and we'll give it the key of five.
04:20
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.
04:42
So that's the general concept dictionaries. You really the uses you're going to get out of. These are just
04:47
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
04:56
in her lab,
04:58
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
05:14
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.
05:24
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
05:43
intro to Python here on Cyber Eri
05:46
on demand.

Up Next

Intro to Python

This is an introductory course on Python for cyber security, giving students the ability to understand the basics of the language, solve problems with scripts and identify useful Python modules.

Instructed By

Instructor Profile Image
Joe Perry
Senior Technical Instructor at FireEye, Inc
Instructor