Time
2 hours 57 minutes
Difficulty
Beginner
CEU/CPE
3

Video Transcription

00:00
Hello, everyone. Welcome back to enter the python here on Cyber Eri on demand I, as always in your instructor Joe Perry and you're in lessons. Seven video to In this video we're going to discussing the python data types, lists and dictionaries and our last video. We covered strings and numbers,
00:17
so a list in python is essentially just an array of data. It's a storage mechanism
00:21
for large amounts of data. So, for example, we might do L. One
00:26
the way you define a list. The easiest way to find a list in Python is with square brackets
00:31
you could also use.
00:33
You also use the list command. I'm personally not a huge fan of doing that
00:38
just because there's not usually much of a need for it. It's usually easier to use the square brackets and then just assign your values directly in it.
00:48
But either way is functional.
00:51
You could see her that I created this list. L won, and now we could
00:55
I can clear my street and fix that we can look at what l one contains just by typing on the line or by printing it.
01:02
Both of those are gonna work the same way in the interpreter in a Python script. If you were actually right this code down into a document, we would have to use print to get it to print to the screen.
01:10
But in the interpreter, you could do either.
01:11
So you can see here that this list exists and it holds a bunch of numbers right now. And you may remember, from our four video are four loop video that we can do things like four I in L one
01:23
prince,
01:26
I swear,
01:29
and you can see there that that will work just fine. Additionally, you can actually perform a lot of other operations with lists. You can, for example, create two lists
01:44
L one and L two
01:49
and combine them
01:56
very easily to create a single list containing all of those datas. Are all of those data's all of those pieces of data?
02:01
Additionally, it's worth noting here that this list contains can contain multiple types of data you can contain multiple times of variable. It doesn't necessarily have to be variables doesn't necessarily have to be strings or numbers. It could be basically anything in python. In fact, you could even have
02:23
a list containing other lists and you can see that demonstrated when we use
02:30
for it is worth noting that depending on your font, it is actually recommended not to use the lower case letter l as a variable name in general, don't you? Single letter variable names. But the lowercase letter l, as you can see here, actually looks like a one and can make the code confusing to read.
02:46
We're not too worried about it right now because we're writing very simple programs, but it is worth noticing.
02:51
Anyway, The point here that you can see is this list now contains three lists, each of which contains strings or numbers. It's very easy to do. You can see I created those with one line commands each time. Very, very straightforward. Lister A really powerful tool that you know, a surprising amount of work with
03:07
We're gonna spend. Like I said in our previous video, we're gonna spend an entire lesson on lists and module two. For now, we're gonna move on to dictionaries. The last python data type we're gonna be discussing in less than six or less than seven. Rather. Um, I'm mixing up my lessons now, so dictionaries are very similar to lists. They're created in a similar way.
03:30
But instead of using square brackets,
03:31
we're going to use braces or curly brackets, depending on who you're talking to. But those air braces and calling them curly brackets makes you sound like a 12 year old.
03:39
I shouldn't say that on video, but I'm going to so moving on dictionary, one that we've created here is an empty dictionary that has no values.
03:46
We can also choose to create it
03:50
with with some initial values in it.
03:53
The way you the way you create values in a dictionary is as what we call key value pairs much like the way you would with a real dictionary, and you're in your office or your home, where you look for the word that you're trying to find the definition of you find that word in the list, and it will show you the definition next to it. Dictionaries and python operated exactly the same way,
04:13
so we can do, for example, for our keys. We might do the string. A is the key for the word
04:16
apple.
04:18
Be
04:20
banana.
04:25
Never know when to stop writing the word banana
04:30
and see if we can do,
04:31
Sherry.
04:33
So here you can see we've created this dictionary with three
04:36
key value pairs, and those key value pairs are associated with one another by using a colon. They're separated
04:44
from each each key value Paris separated from the other key value pairs by commas the same way that items were separated. It enlists, and we just break that out into each of these individual pairs.
04:54
Then, instead of using references like you might with lists which are referenced by index, I actually didn't talk about so I'm glad that I'm glad that we're doing this all in one video, you can reference specific items in lists by using the index number. For example, zero will give you the first item of a list.
05:12
One will give you the second because, remember, we index from zero.
05:15
If you try and find the index of an item that is not in that list, you'll get an error saying that your index is out of range.
05:23
But in dictionaries, you don't address them by using the index in the cell you would list. Instead,
05:28
you address things in dictionaries
05:31
by using the same square brackets. Do you would if it were a list.
05:34
But using the key
05:38
here, you can see by giving it the key of a it returned Apple. Because, as you may recall from creative, the dictionary
05:45
A is paired to Apple as the key to that value. It works exactly the same way with each of them
05:59
very easy to reference. Now it's worth noting that if you try and a reference some key that does not exist in your dictionary, you will get an error, and it's just going to say key error. Five actually think it's gonna be key air
06:10
for
06:12
not what I meant to do. There.
06:14
We're gonna clear this real fast.
06:19
Yeah, So the key area is going to be whatever your input was as the key, and I was just telling you that you're not using a valid key. A lot of times it's gonna be because of the case you need to check and make sure because it is case sensitive.
06:30
It could be really any cause. The point is that you're not using the right key for that particular dictionary,
06:35
so that is lists and dictionaries in python again. Each of those is going to be the subject of its own lesson. They're incredibly powerful tools again, before him. An astonishing array of operations when I spent a whole bunch of time on those in module to. But for now, you are actually done with lessons. Seven of module one,
06:53
which means that you were done with Module one. In our next video, we're gonna perform a summary and review.
06:57
I'm gonna talk about what we've learned in this module, and we're gonna prepare for the midterm that is going to be part of your supplemental materials. That is the end of module one. I hope that you have enjoyed learning with me. And I hope you come back for module two,
07:10
which should be right next on your list. And I'm very, very excited to start really digging into python code and writing some real programs. As always, I'm your instructor, Joe Perry, and thank you for watching Internet Python here on cyber eri 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