All right. So let's begin by talking about lists.
Now, lists aren't anything new to us.
We've actually worked with quite a few lists already.
We've had lists of names, lists of cars and so on.
But the one thing about lists is that they are what we call mutable,
meaning that the items or elements that you have in a list,
we can actually modify them, right?
So we can add to the list,
we can remove from the list and we can modify
whatever elements that already exist within that particular list.
Now, over here,
I do have a list of compromised passwords.
So you know the usual password, 12345, Qwlty and so on.
Now, I want to show you a
few things that we can do in here, right?
I can say print,
ok. And now in brackets,
I can call the list, compromised passwords.
And now I can provide the index number
of the item that I want to list. In this case. Right now, it is
index number zero.
If I run my program, you can see that's going to be password.
So the first thing I want you to understand is that the items in a list,
they all have index numbers starting from zero.
So if I was to print index number two, what do you think the answer would be?
Yep, it's gonna be QWE rt Y
OK.
That's the first thing I want you to understand.
Next is the fact that we can perform various types of functions on our list.
For example,
I can say, let me call the list again
And now
I can add this function here called append
a pen right here
in technical terms is what we refer to as a method.
Methods are also functions,
but they are very special kinds of functions. We'll talk about methods a bit later.
But for now, just understand that we do have very special functions,
functions that are called methods
that you can apply directly onto lists and they will do something.
So right now,
what a pen would do is that it will add whatever new item you want into our list. So
as an example, I can open up my brackets
and let's say we add a swordfish,
OK? This is
a very, very popular
pages
by a lot of people.
OK?
So I've appended salt fish to the list.
So if I go back right now and I print my compromised passwords,
you can see salt fish has been added to the list. So this is the very first
a method of function. I want you to understand that you can use with your lists.
The next one is going to be what we call the extend
function.
See a
pen with a pen, you can add,
you know, individual items, elements and so on. With extend,
you can actually add all elements from another list.
So as an example, I have my first list right there, uh compromised passwords.
And let's say we've created another list
of compromised passwords.
Ok.
Equals and now let me open up
the brackets in here
and let's add some fresh batch of passwords.
Let's see, we have what are the very common passwords people often use?
Ok, let's say 123 AB C.
How about that?
And let me add
one more
and let's call that one dog cat Bone,
you know, just something. All right. Ok. So we now have two different lists, right?
One for the compromised passwords and then
another for the new compromised passwords.
So check this out. Ok, I can come here right now
and say
compromise passwords and now extend
and now in brackets,
I can say new
on this
compromised password. So basically
I am attaching the new passwords into the old passwords list.
And now if I run my program,
now you can see that 123 AB C and Dog
Cat Bone have been added to my compromised passwords list.
Now,
another method I want you to be aware of is going to be quite the opposite of append,
which is going to be remove.
So let me first of all
cut out
our first or second list rather
and I am going to modify this line right here and then say
remove.
And now in brackets,
just as an example, I can provide
what I want to remove, which is 12345.
So let's say I wanted to remove this particular element. Very, very easy.
I'll just say that remove, run.
And now you can see that 12345 is no longer
in the
coin passwords list. So very, very straightforward.
Another one we can do is to simply clear,
we can clear the entire list as an example. So if I was to come over here right now,
change, remove to clear.
All right, I don't need to have anything inside the brackets.
So just clear and if I run,
there you go,
it is going to be empty. There is nothing inside of the list any more.
So there's quite a few other methods that you can work with.
I think it's about 11 of them.
But let me give you two more.
Another more we can use is going to be a reverse.
All right. So basically what this will simply do is that it will reverse
the items in the list. The order is going to reverse the order. So if I run this,
there you go, it starts from
uh let me in and goes backwards all the way to password
and then one more
that I want to show you that can be very useful would be the copy
method. So
as an example over here,
let me just come right here and I'll create a backup. Ok? So
backup and let's say underscore accounts,
ok?
I can assign the backup to my variable backup
account and I can now say equals and now compromised
uh passwords
and now dot
copy
and now in brackets.
All right. So basically what I'm doing right now is I would like to make a backup
of this list, this compromised password list and then assign that
to the variable backup accounts.
So now if I was to print
the backup accounts
and I run,
you will see right now that we have the exact same
list, the exact same item. So
this is what you would use to create backups or copy
the items in a particular list.
So, like I said, you do have a few other ones like salt pop and so on.
We're going to talk about methods a bit later in the course.
But for now that's the introduction to lists and the
methods that you can use to work with them.
Thank you for watching. I will see you in the next class.