0:00
Hello everyone, welcome to the next chapter that is list
0:03
So I'll be explaining the list data types in detail, how we can work on list in Python
0:09
So if you wanted to represent a group of individuals, object as a single entity, where insertion
0:16
order is preserved and duplicates are allowed, then it should be list
0:20
So what is this insertion order and duplicates? For example, I can list something
0:26
This is a name of the list, like an identifier. should start with opening what I says it can have one two three four are these
0:35
digits instead of that you can also have a B one two seen this is only
0:45
digit this is strings and digits so we can have a different data types inside the
0:52
list also this can be duplicates are there so for example instead of one I can have
0:59
multiple entries of the same element right so insertion order is preserved so at whatever order
1:05
first element is there that order is preserved so that means this index will be zero and
1:10
index will be one two and three right duplicates are allowed heterogeneous objects are allowed
1:18
list is dynamic because based on our requirement we can increase the size or decrease the size
1:24
so there are different methods to add or remove the elements from the list
1:29
We will see them one by one. We have seen a lot of methods in strings. Similar way, there are methods in list as well
1:35
So in list element will be placed within the square bracket and with comma separated
1:40
So these are the comma separated and these are in the brackets
1:44
So your list also support the positive and negative index. Both positive means we are starting from this side
1:50
Negative means we are starting from this side. So that means these are on 0 1 2 are positive index and then minus 1 minus 2 minus 3 are the negative index Right so whenever somebody is asking this element 10 it is having positive index of 0 and negative index of minus 1 minus 2 minus 3
2:07
minus 5 and minus 6 right so list are mutable that is we can change the content so in case
2:14
you wanted to change the content of list we can change it we'll see them how in the next
2:19
steps for example how what are the ways to print the list right so there are
2:24
first thing is first is you can take the input from the user we know like we can ask the
2:31
user to view the input using input function and enter the list whenever you are doing you can just
2:36
add one two three all the elements right and then we can use eval function we evaluate those
2:42
input which we convert it into list right and it should see all these elements i have entered
2:49
and it is converted to the 10 20 30 40 50 50 then another one is a list
2:54
In Typecast in we have seen like INT like STR we can also convert the direct input to list
3:02
So for example I am taking 10 elements from 0 to 9 and I am converting into the list and
3:08
that list is stored in any of the variable named L and where I am printing it I am getting an output
3:14
Here I have taken range of 0 to 10 with two steps
3:18
So all 0 to 4 6 8 until 9 will be printed
3:22
Now for example I have a string. To convert it we have already seen in strings we have S dot split so this split function is used to convert elements inside our string as a comma separated list element
3:38
So like this the list will be created. After that how to access those elements
3:44
Just similar way we have seen in the string we can access them using index that is list of 0 is 10 and list of minus 1 is 40
3:53
Similar way by using a slice operation seeing 2 to 7 with the steps of 2 So for example N and release 2 to 7 means this is 0 this is 1 this is 2 2 3 4 6 7 so 6 right
4:08
Since 7 means we will exclude this in steps of 2. Means we will start with 3, then 5, and then 7
4:20
So here is that outfit, right? similar way we are just taking different ranges to get our outputs we can access the element
4:28
with indexes or with range as well right after that there are a few functions that we have seen
4:35
one is length function that we have already seen in strings there is a count function that
4:39
also we have seen and there is an index which will tell the first occurrence of the item there is an
4:44
append see append will be able to add the item at end of the list for example you have list
4:50
with one to three and now you are doing list 1 dot appained 5 so it will append at the last
5:00
then we have insert you can also tell to insert at specific index for example list 1
5:07
dot insert and index 3 and value will be 10 right we can also extend to another list
5:16
For example you have list 1 and you have list 2, you can just do list 2
5:22
.exteemed list 1. So that way your first list and second list will be added together
5:30
You can also remove using remove method. You can also remove using remove method
5:35
You can pop the last element of the list using pop method
5:39
This is important. You are just using pop. It is only taking the last element out of the list
5:45
Reverse will directly reverse the order of elements. Sort will sort you on list
5:50
For example you have a list of 1 5 7 and 9 And then we have 8 3 So whenever you are doing list dot sort it will just sort it out in 1c5 7 and so on right so sort function is used and clear is used to
6:08
remove the all elements from list so that is it from the list we'll see in an in Jupiter
6:14
known book so here the example is I have created a list 1 and stored all those
6:20
values and then I have printing this list 1 now here I am
6:24
taking the input and then I am just doing certain operations right so whatever the inputs
6:29
I wanted to view so it should be comma separated then right whenever you are giving inputs
6:43
it is taking those converting to the list we can convert we can perform certain operations
6:50
we also have a range functions you see this also we haveeked so we have seen using
6:54
using indexes and slicing operations I'm just printing them and then we have a
7:01
different operations like length function count function index function append function insert function whenever I will just do shift enter and all of
7:14
those outputs will be there see all the examples that we have seen we are
7:19
inserting one at index 1 string is inserted at index 0 and
7:24
10,000 insert it. Upend will just do new at the last. Here you can see new at the last
7:31
And then also we can remove this particular element directly saying remove method
7:36
Whenever you are listing the pop, means last element will be popped out
7:40
See 1, 2, 3 4th. 1, 2, 3 4th. So last element is new
7:44
So new one is removed. Similarly, you can reverse it, sort it, and clear it
7:49
Whenever you are clearing it will be empty. That is it from the list
7:53
We will see different data type like Tappell in next chapter. Thank you