WEBVTT

00:00.850 --> 00:09.010
You can add a new element at any position in your list by using the insert insert method.

00:09.370 --> 00:14.950
You do this by specifying the index of the new element and the value of the new item.

00:14.950 --> 00:19.330
In this case, we will make the auxiliary courses that insert here.

00:19.330 --> 00:20.980
First, we will enter the index.

00:20.980 --> 00:29.320
In this case, let's actually add two zero the first index here, and after that we will enter the value.

00:29.320 --> 00:34.240
In this case, let's actually make the let's add new course, the courses list.

00:34.750 --> 00:42.940
And in this case, we will add the computer forensics course and that's it.

00:43.120 --> 00:47.980
So now we will print the auxiliary courses.

00:47.980 --> 00:55.660
And here, as you can see here, under coding training in 33 hours specified and course in the world.

00:55.660 --> 00:58.840
And lastly, we will have here.

00:59.800 --> 01:00.060
Oops.

01:01.060 --> 01:01.730
Combative ranks.

01:01.750 --> 01:10.990
Now, of course, we want to this year, the first year we added the first index with this zero here.

01:11.170 --> 01:19.870
So in this example, we insert a value computer forensics course at the beginning of the list.

01:19.870 --> 01:30.130
So the insert method opens a space position at the zero and stores the value computer forensics course

01:30.250 --> 01:31.090
at here.

01:31.090 --> 01:34.990
So, for example, let's make sure here we.

01:36.170 --> 01:38.710
Oops, let's actually use the boxes.

01:38.720 --> 01:40.670
So one, two, three, four.

01:40.670 --> 01:42.740
We have four boxes, right?

01:45.720 --> 01:46.550
Three.

01:50.400 --> 01:51.990
So here.

01:53.360 --> 02:00.920
If you write like that, it will add the our new value to here and.

02:02.330 --> 02:08.360
Our index Android here is going to be one now from now on here.

02:09.570 --> 02:16.890
Our index Android is going to be one, two, three, four and the newly added.

02:18.180 --> 02:21.360
Computer forensics course is going to be what?

02:21.570 --> 02:22.350
Yes.

02:22.380 --> 02:23.010
Zero.

02:23.520 --> 02:32.010
And as you can see here, this this course is splitted like this, this increase it by one because of

02:32.010 --> 02:33.450
the we added here.

02:33.600 --> 02:43.650
So this operations shifts every other value in the list one position to the right here.

02:43.980 --> 02:47.310
So we can also remove elements from a list.

02:47.310 --> 02:52.200
So actually let's try another example now here one right.

02:52.230 --> 02:53.610
Let's try this now.

02:54.340 --> 02:58.990
And here now we will create the same illustration here.

02:59.080 --> 03:03.730
In this case, for example, one, two.

03:05.890 --> 03:06.670
Three.

03:08.450 --> 03:09.290
All right.

03:10.260 --> 03:14.040
So here we add a new element here.

03:14.040 --> 03:14.650
Right?

03:14.670 --> 03:21.750
So now, from now on, our new element will be added at the here, right?

03:21.780 --> 03:24.150
This in the first index.

03:24.270 --> 03:28.260
So now our element is added here.

03:29.010 --> 03:29.310
Of.

03:31.740 --> 03:34.830
Our element is added here.

03:36.970 --> 03:37.300
Actually.

03:37.300 --> 03:44.890
Instead, we use the blue for the newly added elements and we we didn't touch.

03:45.430 --> 03:46.360
The first element.

03:46.360 --> 03:47.860
So index zero.

03:49.210 --> 03:56.470
And here this index here in this case, Android Kotlin training is going to stay the same, Right?

03:56.470 --> 03:59.230
It will not move or trigger anything.

03:59.230 --> 04:02.830
So it will stay the same.

04:04.310 --> 04:06.440
It will stay the same.

04:09.130 --> 04:13.560
But here we added to this is the new value.

04:13.570 --> 04:16.390
But all of this here three.

04:18.030 --> 04:20.730
Three, four, five.

04:20.760 --> 04:26.700
So here, before insertion, this was two and this was three and this was four.

04:26.700 --> 04:31.350
And there was no computer forensics course in here.

04:31.350 --> 04:34.380
Let's now remove the elements from the list.

04:34.380 --> 04:40.680
So often you will want to remove an item or set a set a set of items from a list.

04:40.680 --> 04:46.080
So, for example, when a player shoots down an alien from the sky, you will most likely want to remove

04:46.080 --> 04:47.850
it from the list of active aliens.

04:47.850 --> 04:53.550
So when a user decides to cancel their account on a web application you created, you will want to remove

04:53.550 --> 05:00.000
that user from the list of active users so you can remove an item according to its position in the list

05:00.030 --> 05:01.560
according to its value.

05:01.590 --> 05:08.610
So if you know the position of the item you want to remove from a list, you can use the Del statement.

05:09.610 --> 05:11.440
So how are we going to do that?

05:11.440 --> 05:14.440
Is now we add it here.

05:15.910 --> 05:17.530
Let's actually leave it here.

05:18.490 --> 05:23.740
Let's actually delete it so the new programmers will not confuse anything with it.

05:23.740 --> 05:25.240
So this is our list, right?

05:25.390 --> 05:28.840
And instead of doing this, let's add to the end.

05:28.840 --> 05:30.400
One, two, three, four.

05:31.020 --> 05:34.410
So zero, one, two, three, four here.

05:34.410 --> 05:35.760
And let's run here.

05:35.760 --> 05:39.720
And as you can see here, it added at the end.

05:39.810 --> 05:41.670
As you can see here, that's it.

05:42.150 --> 05:43.560
So now.

05:44.370 --> 05:48.630
I will also comment that this this is.

05:50.750 --> 05:59.720
This code inserts item to list into, list into list.

06:00.200 --> 06:03.030
And here we will remove an item from it.

06:03.050 --> 06:08.540
So now I want to hear drive again something here which is.

06:08.840 --> 06:11.270
So this is.

06:12.200 --> 06:12.920
One.

06:16.570 --> 06:18.510
We're sorry.

06:21.610 --> 06:23.290
One, two.

06:28.710 --> 06:28.900
Right?

06:29.500 --> 06:30.120
Right.

06:30.520 --> 06:40.150
So here, according to this this element, the computer forensics course goes to here, MySQL goes to

06:40.150 --> 06:40.930
here.

06:41.460 --> 06:44.040
And this poster here.

06:44.070 --> 06:44.550
All right.

06:44.550 --> 06:47.280
Let's actually illustrate it so you will make.

06:48.120 --> 06:49.350
You will understand better.

06:51.190 --> 06:52.960
Yeah, that's it.

06:53.840 --> 06:58.560
So the index of these values are, as you remember, zero.

06:58.560 --> 06:58.820
Oops.

06:58.820 --> 06:59.530
Sorry.

07:00.540 --> 07:03.750
Index of these values are zero.

07:04.650 --> 07:06.510
One, two.

07:08.250 --> 07:10.110
Three and four.

07:10.230 --> 07:10.800
That's it.

07:11.430 --> 07:17.260
So now after that, we will remove that item from the list.

07:17.280 --> 07:20.070
In this case, let's remove the base python.

07:20.430 --> 07:25.440
Let's remove the ethical hacking with python into 20 hours, which is the index for.

07:25.650 --> 07:29.460
Let's actually make it tick on them here.

07:29.580 --> 07:31.200
So here.

07:32.330 --> 07:34.520
We will remove this now, Right?

07:36.500 --> 07:38.120
So Del here.

07:39.870 --> 07:42.900
Oxer the courses and you enter the ID here.

07:42.900 --> 07:44.370
In this you enter the.

07:45.580 --> 07:46.300
Position here.

07:46.300 --> 07:49.660
And in this case, it's two and that's it.

07:49.870 --> 07:54.430
Now, we will print the courses here.

07:54.430 --> 07:59.650
And as you can see here, we have Android coding training here.

07:59.770 --> 08:00.520
Check.

08:01.260 --> 08:02.730
Best python course in the world.

08:03.560 --> 08:04.070
Check.

08:05.700 --> 08:07.470
Designing database models with.

08:08.300 --> 08:10.370
MySQL check.

08:11.040 --> 08:12.990
And computer forensics course.

08:12.990 --> 08:20.700
And as you can see here, we do not have ethical hacking anymore.

08:20.700 --> 08:26.400
So according to this, now the tree has become.

08:27.470 --> 08:29.450
To index.

08:30.240 --> 08:40.530
Index has become index two and index four become index three, and we no longer have index four here.

08:40.530 --> 08:44.820
So this index gone and also it splitted here.

08:44.820 --> 08:52.020
So the design of MySQL here got goes here and computer forensics here goes here.

08:52.020 --> 08:58.020
And in this list we do not have the index four anymore, but we deleted.

08:58.050 --> 09:00.300
Ethical hacking from the index two.

09:00.450 --> 09:02.910
This is how the list works.

09:02.910 --> 09:10.020
So in this case let's actually try what will index four give us here?

09:16.020 --> 09:20.130
Or actually, yes, let's actually instead of this, let's print the value.

09:21.320 --> 09:21.650
So.

09:22.580 --> 09:24.050
Print the value.

09:25.790 --> 09:30.110
Oxer the courses and print the value for all four.

09:30.500 --> 09:32.480
And here, as you can see here.

09:32.510 --> 09:35.940
List index out of range.

09:35.960 --> 09:43.310
This is the reason that gave us because there is no anymore fourth index here.

09:43.580 --> 09:48.380
So actually, instead of this we here, let's actually undelete this.

09:49.520 --> 09:51.710
And yes, perfect.

09:55.030 --> 09:55.540
Perfect.

09:56.700 --> 09:57.270
That's it.

10:14.760 --> 10:18.900
Now let's remove the another item from the position here.

10:20.150 --> 10:23.600
And now let's remove Del Oxley courses.

10:23.630 --> 10:26.390
Let's actually remove the item zero.

10:27.410 --> 10:28.610
And now.

10:31.330 --> 10:33.340
Actually, we don't need that code anymore.

10:35.310 --> 10:36.410
And that's it.

10:36.420 --> 10:40.340
As you can see here, we have left with three items in the list.

10:40.350 --> 10:41.310
So.

10:44.250 --> 10:45.030
That's it.
