WEBVTT

00:00.990 --> 00:07.670
Hello, everyone, in this particular session, we will discuss about list, we will see how to create

00:07.680 --> 00:14.850
a list, how to retrieve elements of a list, how to add different objects to a list, how to insert

00:14.850 --> 00:18.900
element at a particular position, and how to remove objects from a list.

00:19.530 --> 00:22.670
We would also see how to sort the list now.

00:22.710 --> 00:25.320
First, we begin with the list.

00:25.560 --> 00:29.570
Let us discuss about the different characteristics of a list.

00:29.820 --> 00:33.750
So the first thing about list is that list is ordered in nature.

00:34.020 --> 00:40.050
Ordered in nature means that we will be able to retrieve a particular element from a particular index.

00:40.380 --> 00:42.160
Hence it is ordered in nature.

00:42.750 --> 00:44.250
Next is mutability.

00:44.460 --> 00:45.900
Now what does mutability?

00:45.900 --> 00:53.940
Mutability is a concept where a particular database allows us to change the element itself.

00:53.970 --> 00:56.900
It allows us to change a particular value.

00:57.390 --> 01:01.710
So if we talk about strings, strings are immutable in nature.

01:01.710 --> 01:02.740
How can we see that?

01:03.000 --> 01:08.400
So let's say we have a string as I try to modify a particular character.

01:08.610 --> 01:13.680
Is same at index for I want to put.

01:15.020 --> 01:21.480
Let's I want to put a character B, let's say I want to put the character so.

01:22.430 --> 01:26.340
We get the error that string object does not support an assignment.

01:26.540 --> 01:32.300
So this means that string cannot be modified, a particular index of string cannot be modified, although

01:32.420 --> 01:34.520
if you try to do something like.

01:36.520 --> 01:43.660
S is equal to be something, something so we will be able to do that not just because we are trying

01:43.660 --> 01:46.320
to replace the entire object.

01:46.330 --> 01:48.780
So here we are creating a new object.

01:48.940 --> 01:52.940
It is an entirely new strain being assigned to the variable.

01:53.590 --> 01:54.840
So this is possible.

01:55.060 --> 02:01.870
But when we try to modify a particular index of a string that is not allowed because string in itself

02:01.870 --> 02:03.690
is immutable in nature.

02:04.000 --> 02:10.390
But when we talk about list list as movable in nature, so because of that we will be able to modify

02:10.390 --> 02:10.840
a list.

02:10.850 --> 02:12.250
We will see how we can do it.

02:12.520 --> 02:13.330
But after some.

02:14.110 --> 02:18.040
Now let's see how it supports multiple data.

02:18.610 --> 02:23.640
So in case of a list, we will be able to add different type of data types.

02:23.860 --> 02:30.040
So you would have seen that in some languages it is allowed to add only one data that you can have a

02:30.040 --> 02:32.440
string or you can have a number.

02:32.650 --> 02:40.330
But in case of list invited, we will be able to add any mixture of different types.

02:40.570 --> 02:43.380
So let's first of all see how do we create the list.

02:43.570 --> 02:45.910
So first of all, we will have to give a variable.

02:46.180 --> 02:52.460
My name is Enlistee one and I want to add certain elements to it.

02:52.480 --> 02:58.450
So let the elements be string a B next element.

02:59.470 --> 03:05.290
Methe next element be one, then two, then three.

03:05.530 --> 03:08.260
Let's have another element that's true.

03:10.610 --> 03:16.850
And another element does fault, so you can see I can have different combination of values in the list.

03:17.270 --> 03:21.390
Now this is my list and just my list for you.

03:21.590 --> 03:22.850
So this is my list.

03:23.210 --> 03:31.610
Now, in case you want to retrieve a particular element from a list, we can do it by say.

03:32.840 --> 03:36.680
LSD one and I want to retrieve the zeroth index.

03:37.220 --> 03:39.660
We can do it by Elstein one zero.

03:39.890 --> 03:45.710
Let's say we want to retrieve the last element so I can do it by using minus one.

03:48.280 --> 03:53.110
Sorry, I don't have anybody, I have it is the one, so if I do a listed one, I am able to retrieve

03:53.110 --> 03:55.210
the last element, which is minus one.

03:55.570 --> 03:58.690
Now, let's say we want to retrieve NSD one.

03:58.990 --> 04:06.670
We want to retrieve the this particular element, which would be minus one, minus two, minus three.

04:07.030 --> 04:12.400
We want to retrieve the negative third element and it comes out to be three.

04:12.790 --> 04:15.780
Now, let's say we don't want to retrieve just one element.

04:15.790 --> 04:17.980
We want to retrieve multiple elements.

04:18.250 --> 04:19.350
How would we do that?

04:19.600 --> 04:22.890
We do that by saying the last one.

04:22.900 --> 04:26.230
I get that all the time and see one.

04:26.230 --> 04:34.000
And after that we say from zero the next to now, we also need to see how we can find out the entire

04:34.000 --> 04:36.700
length of a list so we can use then.

04:38.060 --> 04:43.480
And we can give amnesty one inside this, so this gives me the entire length of the middle of my list

04:43.490 --> 04:47.080
of seven so I can go up to six.

04:47.270 --> 04:51.490
So let's say six so I can see all the elements.

04:51.680 --> 04:56.830
And remember, in slicing, what happens is this is the starting point.

04:57.020 --> 05:03.260
And when I say six, this means that I want to retrieve element from zero to five.

05:03.530 --> 05:07.400
Six means that six is not supposed to be included.

05:07.560 --> 05:13.760
If you want to get all the elements, you just put nothing and retrieve all the elements.

05:14.060 --> 05:18.010
And if you give seven year, then it would give all the elements.

05:18.260 --> 05:24.230
So what you put here is the last element which you want to retrieve plus one.

05:24.250 --> 05:29.060
Always remember that this last element which you want to retrieve plus one.

05:30.930 --> 05:37.430
Now, the next thing which we can do is let's say if you want to retrieve the elements ultimately and

05:37.440 --> 05:44.400
we want to skip one element in between piquancy to this means that we want to skip one element in between.

05:44.430 --> 05:48.150
So if I retrieve this, I get the alternate values.

05:48.810 --> 05:54.780
Now, the next thing which I can do in is let's say if I want to add different objects to a list and

05:54.780 --> 05:56.720
let's say you want to combine different list.

05:56.940 --> 06:03.430
So let's create another list, say let's do it on my list or I will put in some numeric elements.

06:03.600 --> 06:06.570
One, two, three, four, five, six.

06:06.900 --> 06:15.270
And if I want to join these two list, I can simply say enlistee is equal to L'Estang one plus Amnesty

06:15.270 --> 06:15.720
two.

06:15.900 --> 06:23.480
And now if I print my list, I will give get a list, which has all the elements of list one and two.

06:23.700 --> 06:28.380
And if you see these have all the elements from list one list.

06:30.460 --> 06:40.120
What else I can do is I can also use dot up and now when they use dot up and this means that you want

06:40.120 --> 06:49.720
to add values, which are a single line, you now dot up append, always add whatever you given as an

06:49.720 --> 06:55.850
argument in just one single index, it will be added to the next index, which we have.

06:56.170 --> 07:04.470
So here, let us see the next index, let the same list one and see this one.

07:04.780 --> 07:08.500
And if you see this, do you see the length of to.

07:10.910 --> 07:19.960
So the length of two is six, so this means that we have values from zero to five already present,

07:20.210 --> 07:24.140
but there is no value on the index.

07:25.700 --> 07:35.060
Seven and six, so let's say let's do an index six, so you will see that there is no value present

07:35.060 --> 07:35.330
here.

07:35.600 --> 07:42.980
Now, if I want to add certain value, what I can do is I can simply saying this to not offend.

07:44.650 --> 07:48.050
And inside this, I won't give any object which I want to I.

07:48.370 --> 07:50.200
So let's say I want to add.

07:51.400 --> 07:53.520
Under number eighty nine.

07:56.490 --> 07:57.220
Eighty nine.

07:57.540 --> 08:02.400
And let me bring up the list to after this.

08:06.050 --> 08:13.550
So you can see the element which we added has been under that nasty mix, now, let us try one more

08:13.550 --> 08:13.820
thing.

08:13.820 --> 08:16.850
Let us try to append another list.

08:17.180 --> 08:17.870
Let us see.

08:17.870 --> 08:19.730
We tried to open the list.

08:22.290 --> 08:33.060
Of elements, eight gunmen, nine gunmen then, so now what will happen is it upend the list entirely

08:33.300 --> 08:40.890
in the next index, so it does not believe, I believe, over the elements and add them in two different

08:40.890 --> 08:41.640
indexes.

08:41.940 --> 08:47.640
It just picks out the object and puts it in the mixed index, which is available.

08:47.970 --> 08:52.980
Now, in case we don't want this thing to happen, then what we can do is.

08:54.330 --> 08:57.090
We can simply use.

08:59.720 --> 09:00.770
Extend.

09:01.730 --> 09:07.430
What extend does is let's say we want to have 11, 12.

09:09.370 --> 09:18.220
13 and 14, so what extend would do is it will I trade over this entire list and it will add the element

09:18.220 --> 09:23.530
at the end of the list and it will add them into different indexes.

09:23.800 --> 09:25.270
So let's do that.

09:25.420 --> 09:28.180
So now you see these elements were added.

09:28.190 --> 09:35.200
And one thing, the index like 11, 12, 13, 14, they have been added in two different indexes.

09:35.200 --> 09:41.560
It actually I traded on top of the list, which we provided and added the values and different elements.

09:51.280 --> 09:57.430
Now, let's try to do one more thing, let us try to instead of having this entire thing for discussion,

09:57.940 --> 09:58.900
let us try not.

09:59.200 --> 10:01.840
So let us try out a string.

10:01.840 --> 10:02.620
Try to it.

10:03.130 --> 10:05.650
OK, let me copy this.

10:06.490 --> 10:14.540
And word this fact, what we want to be had, so let me add more cells here.

10:14.560 --> 10:16.440
So now let us try this.

10:16.750 --> 10:23.220
So it added these elements in two different indexes because DLI is a string.

10:23.230 --> 10:26.280
And as we know, the string is a collection of characters.

10:26.530 --> 10:32.830
So it added I drifted over the string and added these characters one after the other one.

10:35.080 --> 10:41.400
The next thing which we can do is we can add elements of the political opposition using bought and sold.

10:41.650 --> 10:48.880
So let's say we have a list to, again, see a list to do, and we want to do it in sort.

10:49.150 --> 10:53.530
And we want to insert an element, our position C three.

10:53.830 --> 10:57.530
And the object, which we want to insert is new.

10:59.770 --> 11:03.010
And let's bring in as to do so.

11:03.010 --> 11:04.960
This is the new list.

11:05.290 --> 11:10.540
The new object has been added of the index three and how we verify index three.

11:10.540 --> 11:11.410
This is zero.

11:11.710 --> 11:13.810
One, two, three.

11:13.960 --> 11:15.610
So add the third index.

11:15.610 --> 11:17.500
This new object has been added.

11:18.010 --> 11:19.800
Now, that is another thing.

11:19.810 --> 11:23.020
Let us try to remove objects from a particular list.

11:23.020 --> 11:31.810
So to improve in to remove objects from a list, we can do enlistee, do dot remove.

11:32.140 --> 11:40.710
Now let us try to remove the element three from it, so let's try to remove three.

11:40.990 --> 11:44.110
So we will simply give three here and then print.

11:44.500 --> 11:50.710
And unless to do so, the element three has been removed from this particular list.

11:51.070 --> 11:57.100
Now another thing which we can do is we can do something we can use and see pop.

11:58.440 --> 12:05.610
So ListBox will remove the last index by default, so if I do something like.

12:07.130 --> 12:17.510
Doubtful it will remove the last element for us and it would bring down the value to us, it will return

12:17.510 --> 12:18.400
the value to us.

12:18.560 --> 12:21.070
So let us print.

12:23.230 --> 12:26.620
While you and Leather's rent.

12:29.690 --> 12:37.930
And so once we run this, it has blocked the volume from the last index, which was which was why?

12:38.510 --> 12:40.490
Because we have not given any argument.

12:40.490 --> 12:42.530
We have not given any particular index.

12:42.540 --> 12:46.040
So by default, it assumes that we want to pull from the last index.

12:46.340 --> 12:50.030
So it removes the last index from it.

12:50.420 --> 12:56.580
And the president does and the list is updated with removal of the last element.

12:57.020 --> 12:59.870
Now, apart from this, we can also do one more thing.

12:59.870 --> 13:01.820
We can do another.

13:04.040 --> 13:12.080
Index so we can provide another index save for so let's say we want to pop out index for some before

13:12.080 --> 13:13.400
popping out index for.

13:13.400 --> 13:15.630
So let's try to bring this one.

13:15.920 --> 13:20.450
So when we run this, the object from the fourth index has been removed.

13:20.460 --> 13:24.890
So zero, one, two, three, four.

13:25.010 --> 13:33.680
So the fourth index has value five index, which has been removed and the list has been updated without

13:33.860 --> 13:34.220
the.

13:35.710 --> 13:36.800
Index five.

13:38.530 --> 13:45.340
Now, the next thing which we can do is we can sort the list to sort of list, we can do something like

13:45.340 --> 13:46.240
LSD to.

13:47.120 --> 13:51.940
Don't start now when we started this particular list.

13:52.360 --> 13:58.540
Notice that we have numbers also, we have got those also and we have a list also.

13:58.720 --> 14:01.420
So it is a mix of different type of elements.

14:01.690 --> 14:07.990
So now if I try to sort the list, it gives an error because it cannot really compare these different

14:07.990 --> 14:08.850
types of lists.

14:09.130 --> 14:13.540
So let us try with another list, a simple list.

14:13.930 --> 14:16.140
So let us try this.

14:16.150 --> 14:18.310
And that is great on the list now.

14:18.790 --> 14:32.080
So let's say list for and list four letters have values like one five three seven nine and forty four

14:32.080 --> 14:38.500
and nine nine different lists and us sort this list.

14:41.070 --> 14:45.570
So once we saw this and bring the list.

14:46.450 --> 14:48.670
Sorry, list for.

14:50.360 --> 14:55.760
You can see them, this has been sorted, another thing which we can do is we can you sorted.

14:56.920 --> 15:02.110
Missed and we have option to reverse this also so I can give.

15:03.180 --> 15:12.450
List for it, and it can sort of in reverse order and give us a list, so these are different kind of

15:12.450 --> 15:16.320
methods and functions which we have list which we can use.

15:18.240 --> 15:20.830
This is what we had for this particular session.

15:21.270 --> 15:28.560
I hope you understood this in the next session, we would go through the loops and conditions.

15:28.920 --> 15:29.400
Thank you.
