Hello and welcome to this lecture.
This will be the first lecture on that at a Stokes's so in this lecture we're going to cobalt about
the list the most to use that I stuck to in the python.
So first of all what is list.
So um first of all this come with the variables so when it is a variable you have to store only one
element to the variable so you cannot store something like var saying three is to me 4 5 6 6 add this
to not be valid in the variable you can store only one item to the variable but if you want to store
multiple item to the same variable it is to be done with that that a stock says it can be there this
it can be the least it can with a tuple.
So let's see about the list in dyslexia.
So let me just say my list and I'll say these empty square records.
So when as a save this and if you want to print it in the spring to you my list and it is your empty
list so let me just press a 5 2 so you will be here and if I say my list and assign is empty square
brackets Obadiah then you see that you'll just have the my list is empty.
So you are just creating here the empty list.
So let's assign some of the integers over here so I'll just say my list and let's see one two three.
So now you can see we have a multiple that item to the same variable name which is basically the that
is doctors which is the list.
So we I created the list of phone numbers from 1 to 3.
You can also make a list with the mixed data types.
So we have learned from the previous couple of lectures we have a couple of types.
The visit fundamental data types in a pattern that is first is in desire.
Obviously the one integer and next one is decimal.
And the next one is the string.
And next one is your boolean.
So let's close this first.
And up to this list add the boolean and it is also valid if is a spring to your list you will see this
is going to create us a simple list containing all of the mixed data types so we're here having an integer
float string and a boolean.
So we have created the list over here the first list which is going to get all of the dot items stored
in it.
So you can also have the nested Lee So let me just take example my list and let me say it is going to
have here first and after that then other list after that the more I know the list
after that I know the list again.
So you can see we have created a list which contains the nested list which have more than one list.
So it had one list of well then the list away.
So this is the nested list.
So let's see how we can assist the element from the list.
You can see we have created our list over here which is the mixed list n over here.
We have created our my list.
So let me just copy this and paste to here and now we have the my list containing a mixed data type
so let's assess some of this item from this list.
So in order to assist the element you have to go through the index.
So what is index here.
So index can be assigned with this square regular again.
So in the list the first item is it index 0.
So this is the position which we call 0.
Next one will be 1 2 and 3 incremented e time by 1.
So if you just call this is 1 This should be two and this will be three and always remember the list
index is start from zero not the one.
This is not one it starts from 0.
So if I say my list all then it is going to give us 1 and if I say my list and this time of 1.
Okay
1 and it is going to give us the second element of the list.
But the index having one.
So this is the way to this is Sister lists.
If you want to have this to be printed you can do in two ways.
I'll say my list.
First way is to count from 0 1 to 3.
It should be a three.
And another way is to have the negative indexing.
So this is important negative indexing is from the minus one.
If you want to print this true it should be at minus 1.
And you have to this set decrement.
Again it should be minus 1.
It should be minus 2.
It should be minus three and minus four.
If I want this one it should be minus four which is called the negative indexing over him.
So we have got to 1 which is at the position of minus 4 which is our negative indexing.
So next thing is to slice the list now slices to get part of the list.
We want to get the multiple element of a list is a slice.
So same as the pizza slice.
We want to get some part of the list.
So in order to get some part of lists let me create big list for now.
So instead of just this list it means clear open the new console.
And now let me the script now.
Big list over here.
So this will contain the basically okay let's say 1 2 3
so the random elements over here
so let's close this list.
We have created the list.
So now what if we want to do is we want to have that element from this maybe from three to maybe 66.
We want every element from this three to 66.
So let's see how we can get that.
And this technique is called slicing technique.
So first of all we have to go through the index again.
So 1 is at 0 1 2 is it 1 and 3 is it position 2 but position 3 but index is 2.
So will this go from two.
Because we want to include three and we have to give the Golan and we want to read it 66.
So this is is two three four and 66 is five.
So if you a sparse five year this is the explicit position.
So this is not included if you want to include this fifth position.
You have to pass six because this position is going to be ignored.
So sixth sixth position here are the sixth index is it seven.
And this is not included.
Only up to here is to be included.
So if I hit enter it also was three four five sixty six seven is not included though it has the index
of six.
But this is the ignorable position or this is not included position if you despise my list and from
two to five again which is the position of sixty six index it would just give us three four five.
But not sixty six.
This is the ignorable position and now you can also do something from the beginning to maybe from here
beginning to five if you want from beginning to five we can do something like leave the first position
if you leave first position it will just defiantly start from the first index and discount from the
root.
One two three four.
We want to five.
That means we have to include this fit and let's close this.
So it is giving us one two three four five.
So the next thing is the is step position.
So let's see this step position.
So the simplest and the first one is default.
This the second one is also default.
If you pass third one.
So this third one is basically step.
So each step is the loop are basically what is to be included if I pass to over here it is going to
leave one step in each of the elements so you can see if we just pass two over here.
This one was printed but instead of printing two it has directly jumped to three it has lived out to
four taps lived out sixty six so one step has been not included in the output list if I see something
like my list again go from beginning if you don't pass anything it will go from beginning and again
if you don't pass anything over here it will just go Delaine and if I see three over here and if I print
now again it is going to remove the two element so each step has been three here.
That means it is going to remove that element from each of these part so you can see 1 4 7 2 has been
printed with this slicing technique.
Now let's see some of the important matters of the list.
So first of all I'll make the order limit over here.
1 3 5 7.
So now if you want to append or add another element we can make use of this append method of the list
and I'll say the next would be nine and now if I print out you would see now 1 3 5 7 9 9 has been appended
to this the list so you can do similarly.
Let me say if you want to add multiple element so in the case of append you can add only one element
but if you want to add multiple element you can simply do extend eleven 13 15 and now okay.
What we have just done here was we have to extend with the list so we have this many small mistake over
here because this should be easier able it has sown right over here and we haven't pass in the list
so as 11 13 and again 15 closed the list closed the method and if is a sprint or now it has been extended
so 1 3 5 7 9 was the initial odd now eleven 13 15 was added from this extended method of these Python
list so you can also do something like insert lists go back again again print this and if I say hard
is one in nine and now if you want to insert the element you can simply do insert and now if I say 1
and 3 okay or do this deed over here was we wanted to add this tardy element in the first position.
So this insert method will take the position where do you want to insert out basically the index.
So index is basically the one that means we want to insert in the middle of the one in nine because
one is at 0 9 is it is it 1 percent but now in this position we want to add 3.
So when is this insert this print or you'll see 3 has been inserted now in the middle of one in nine.
So this the way to this insert the element using this Insert method next is to see our removed method
delete method.
So let's see about that.
So first of all let's see our list.
So let's create the new list and as you want to do so list so next thing is to the set delete the list.
So I'll say I want to deliver some part of the list some element of the list you can do that by using
this my list and the slicing technique that we have is sturdy I want to just delete from two to three.
So if I do that and if we say my list again you will see that it has now 1 3 4 5 5 0 2 and 3 has been
deleted.
So next thing you can also do is simply call delete and if we say delete my list whole list will be
deleted and you'll see this my list is not defined because we have just deleted our my list completely
from here.
So next thing is you can also make use of the remove method in order to delete some element of the list.
So let me create my list again and here as say A B C and D are the limit of the list.
And if we want to remove you have to call my list again and thus add the removed method.
So when it is remove let me say I want to remove a C from here.
And if I just print again my list you'll see C has been removed from your list.
You can also do same tax using the pop method so you can see that my list and Dot pop pop method is
off the list and you have to parse the index in this pop method.
So when I say 1 1 is the position for this B So B has been popped out it means element has been popped
out from this list.
So if users D something like my list dot pop it is going to give us it's a default.
The last element of the my list which is in this case the pop.
That means it is going to get the last index which is minus one index.
If default values pass or nothing values passing the pop method it is going to get us the last element
of the list.
So this other couple of points was that important functions of the Python list.
So we have a couple of legacies to learn about that that a Stokes's in the upcoming later we have seen
bundles of the method like insert like pop method and remove insert append every method which is important
in the list.
You can also take a look on this Len method which is going to give us the length of the list and this
is the one because we have just popped out every element.
Only my list has the one element which is a.
So it is going to give us the length of the list is a one.
So this other couple of fun since we have learned in the selector in the next couple of lecture we also
see about the more advanced that structure.
Soon the next one.