WEBVTT

00:00.920 --> 00:07.580
Most lists you create will be dynamic, meaning you will build a list and then add and remove elements

00:07.580 --> 00:09.980
from it as your program runs its course.

00:10.100 --> 00:15.590
For example, you might create a game in which your player has to shoot aliens out of the sky.

00:15.860 --> 00:21.800
You could store the initial set of aliens in a list and or remove an alien from the list each time one

00:21.800 --> 00:23.120
is shot down.

00:23.120 --> 00:27.680
So each time a new alien appears on the screen, you add it to the list.

00:27.710 --> 00:35.150
Your list of aliens will increase and decrease in length throughout the course of the game.

00:35.150 --> 00:42.290
So now the syntax of for modifying an element is similar to the syntax for accessing an element.

00:42.290 --> 00:49.700
Unless you change an element, you use the name of the list followed by the index index of the element

00:49.700 --> 00:56.690
you want to change and then provide the new value and you want to item to have.

00:56.720 --> 01:00.960
For example, say we have a list of course, topics.

01:01.870 --> 01:02.050
On.

01:02.050 --> 01:04.600
The first item in the list is car.

01:05.610 --> 01:08.130
The car is not actually called subject name, right?

01:08.130 --> 01:15.780
So we can change the value of this first item after the list has been created.

01:15.990 --> 01:19.230
So now we will use the.

01:20.850 --> 01:22.320
Course topics.

01:22.590 --> 01:23.280
Right.

01:25.220 --> 01:27.680
Power is the zeroth element.

01:28.340 --> 01:33.470
Index is zero and we will make this car repair.

01:33.500 --> 01:36.470
The car repair is actually like a course topic, right?

01:36.620 --> 01:37.410
That's it.

01:37.430 --> 01:41.930
So now we will print the.

01:42.740 --> 01:43.430
Course.

01:43.430 --> 01:45.650
Or let's actually print the.

01:46.400 --> 01:48.880
Course Topics and index zero.

01:48.880 --> 01:50.140
Let's print the car repair.

01:50.140 --> 01:50.740
Right.

01:51.370 --> 01:53.230
Let's know how it affected here.

01:53.230 --> 01:56.890
As you can see here, car repair has changed.

01:56.890 --> 02:01.330
Here we define the the course topics with.

02:02.160 --> 02:02.420
Car.

02:02.580 --> 02:03.910
Car as the first element.

02:03.920 --> 02:08.340
And we change the value of the first item to car repair.

02:08.360 --> 02:15.380
The output shows the first item has been changed while the rest of the list stays the same.

02:15.710 --> 02:19.160
So you can change the value of any item in a list, not just the first item.

02:19.160 --> 02:20.560
For example, let's.

02:21.290 --> 02:24.030
2012.

02:24.050 --> 02:27.800
So instead of it changing to car repair, we will make it.

02:28.460 --> 02:31.250
Let's actually make it the.

02:33.490 --> 02:34.510
Kotlin, right?

02:34.540 --> 02:35.370
Kotlin.

02:35.380 --> 02:36.730
Let's try it now.

02:36.730 --> 02:42.100
And as you can see here, oops, We need to also change the print function because we are now seeing

02:42.100 --> 02:44.740
the elements zero, not two.

02:44.920 --> 02:48.160
And as you can see here, we have a Kotlin.

02:49.520 --> 02:54.110
So also you want want to add a new element to a list for many reasons, right?

02:54.110 --> 03:01.120
So, for example, you might want to make a new aliens this funny aliens to appear in a game.

03:01.130 --> 03:08.180
Now you add a new data to a visualization or add a new registered users to make a website your build.

03:08.180 --> 03:14.540
So Python provides several ways to add new data to existing lists.

03:15.740 --> 03:20.240
So now let's let's start with the appending element.

03:20.250 --> 03:21.700
So the end of the list, right?

03:21.710 --> 03:26.120
So now we can also delete this alias here.

03:26.930 --> 03:28.370
So here.

03:29.390 --> 03:34.970
The simplest way to add a new element to a list here.

03:37.190 --> 03:41.330
So the simplest way to add a new element to a list.

03:42.080 --> 03:45.330
Is to append the item to the list.

03:45.350 --> 03:51.650
So when you append an item to the list, the new element is added to the end of the list using the same

03:51.650 --> 03:53.240
list we had in the previous example.

03:53.240 --> 03:54.680
We will add a new element.

03:55.160 --> 03:56.240
New element.

03:56.420 --> 03:58.760
Let's make Kotlin or Swift Write.

03:59.500 --> 04:03.460
So now we will write course topics.

04:03.490 --> 04:08.080
Course Topics dot append.

04:08.320 --> 04:10.840
Here we will enter the Kotlin.

04:10.840 --> 04:13.930
Also we will make the course topics.

04:13.960 --> 04:18.310
Course Topics that append Swift.

04:19.460 --> 04:20.060
Swift.

04:20.810 --> 04:25.460
And we will also have course topics that append.

04:26.660 --> 04:28.100
C sharp or.

04:29.630 --> 04:30.440
C-sharp here.

04:30.800 --> 04:34.970
Now, what we're going to do is now there's a here.

04:35.090 --> 04:38.760
So let's write that down what we have as a list.

04:38.780 --> 04:44.390
So here we have item 012.

04:45.250 --> 04:46.810
Pray for.

04:51.370 --> 04:53.470
One, two, three, four, five.

04:55.940 --> 04:57.400
Of let's make it.

04:57.410 --> 04:58.970
Let's actually make it from here.

04:59.920 --> 05:04.240
Zero one, two, three, four.

05:05.590 --> 05:06.280
Five.

05:07.840 --> 05:08.320
Thanks.

05:10.650 --> 05:11.580
One, two.

05:13.270 --> 05:15.480
Three, four, five, six, seven.

05:15.490 --> 05:16.000
Here.

05:16.180 --> 05:17.770
And seven.

05:18.380 --> 05:21.860
So here we will make this like that.

05:27.810 --> 05:28.260
Here.

05:40.660 --> 05:41.230
So.

05:42.240 --> 05:43.440
In first list.

05:44.790 --> 05:47.160
Remember, we had the.

05:47.950 --> 05:49.330
Actually here.

05:49.330 --> 05:52.450
So in verses we have car right?

05:52.600 --> 05:53.410
Car.

05:56.400 --> 05:56.910
Are.

05:58.260 --> 06:00.060
The first is Kotlin.

06:01.060 --> 06:02.500
I will make it short.

06:02.830 --> 06:05.350
Kotlin or Android.

06:05.350 --> 06:07.540
Here A and.

06:10.170 --> 06:12.600
Here and Java here.

06:14.570 --> 06:16.070
Var python.

06:21.330 --> 06:26.170
And digital forensics DVR.

06:26.280 --> 06:27.660
I will make it short here.

06:29.820 --> 06:30.100
Was.

06:37.570 --> 06:38.050
He.

06:40.630 --> 06:41.020
He.

06:43.130 --> 06:44.660
Are digital forensics.

06:45.140 --> 06:50.600
And here remember we added here items, right?

06:54.300 --> 06:57.150
So these items were Kotlin.

06:57.270 --> 07:00.750
So remember, Kotlin added first year.

07:00.750 --> 07:02.910
So after this we are adding Kotlin.

07:02.910 --> 07:05.640
So the Kotlin will be added first.

07:05.640 --> 07:07.950
In this case, it's going to be Remember what?

07:09.350 --> 07:10.030
Remember?

07:10.040 --> 07:10.640
Remember?

07:10.640 --> 07:11.120
Yeah.

07:11.150 --> 07:14.210
Kotlin is going to be fifth item on the list index.

07:16.250 --> 07:16.700
But.

07:17.560 --> 07:17.950
Lynn.

07:19.010 --> 07:19.460
Or no?

07:19.460 --> 07:19.880
Yes.

07:19.880 --> 07:21.170
Kotlin here.

07:21.170 --> 07:23.690
And we also have the swift here.

07:24.080 --> 07:27.140
It's gonna it's added secondly.

07:28.440 --> 07:30.960
So are we going to make it six item?

07:33.820 --> 07:34.090
We're.

07:35.010 --> 07:42.030
Because as you remember here, this function appends at the end of the list.

07:42.270 --> 07:47.580
So if you Kotlin ends here, here, Kotlin is here.

07:47.760 --> 07:49.440
After that, we are adding sweat.

07:49.440 --> 07:59.340
So Cutlan Swift is after Kotlin and we add the C sharp because C sharp is after the swift.

07:59.580 --> 08:00.150
So.

08:00.150 --> 08:02.910
And we also have C sharp here.

08:04.540 --> 08:05.410
That's it.

08:05.440 --> 08:09.930
Here we add the append method.

08:09.940 --> 08:17.250
Add three items to the end of the list without affecting any other elements in the list.

08:17.260 --> 08:20.890
So the append method makes it easy to build the list dynamically.

08:20.890 --> 08:26.950
For example, you can start with an empty list and then add items to the list using series of append

08:26.950 --> 08:28.620
calls using an empty list.

08:28.630 --> 08:35.230
Let's add the elements to our core, to our list here.

08:35.230 --> 08:38.140
So now let me look at the first lecture.

08:38.140 --> 08:39.490
Yeah, that's okay.

08:39.550 --> 08:46.330
So now we will instead of this, we will add and also use this here.

08:46.780 --> 08:49.210
So now we will create a new list.

08:51.390 --> 08:58.050
Actually, let's actually, instead of let's print the list course topics to show you what changed.

08:58.080 --> 08:58.950
Seven.

09:00.310 --> 09:02.190
And as you can see, it's C-sharp.

09:02.380 --> 09:05.470
Six is swift.

09:08.960 --> 09:11.480
The fifth is Kotlin.

09:11.510 --> 09:12.500
The fourth is.

09:12.530 --> 09:14.750
And as you can see, these are not changed.

09:14.780 --> 09:16.100
Affected by the change.

09:16.880 --> 09:18.110
These are not here.

09:18.110 --> 09:20.240
And as you can see, one.

09:20.330 --> 09:21.560
Lastly, zero.

09:25.110 --> 09:26.010
Now.

09:26.950 --> 09:31.330
I will take this note here and I will share this file with you.

09:33.190 --> 09:39.120
Now here we will delete these quotes here and instead we will add course.

09:39.920 --> 09:42.370
Or let's actually course names, right?

09:42.580 --> 09:45.910
Course names or courses here.

09:45.950 --> 09:48.130
Oxley Courses.

09:48.800 --> 09:52.480
And here we will make the list.

09:52.490 --> 09:52.940
Right.

09:52.940 --> 09:53.780
So.

09:54.660 --> 09:59.880
If you do write this code, this will create the.

10:00.960 --> 10:01.890
This will.

10:06.720 --> 10:07.590
I'm sorry.

10:08.480 --> 10:11.780
So this will create.

10:13.260 --> 10:14.370
Empty list.

10:21.490 --> 10:26.800
This will create an empty list here and you can add or delete later.

10:27.610 --> 10:35.110
So now, since we created this, the append method makes it easy to build list dynamically.

10:35.290 --> 10:38.380
So now we will use auxiliary courses.

10:38.380 --> 10:41.740
So the courses that append, we will add new course.

10:41.740 --> 10:42.310
Right?

10:42.670 --> 10:47.500
Android Kotlin training in 33 hours.

10:50.590 --> 11:00.850
And here after that we will Oxley courses that append Python training best Python course in the world.

11:00.850 --> 11:01.450
Right?

11:01.720 --> 11:04.120
In the world.

11:06.320 --> 11:08.330
The excellent courses that are pending.

11:09.170 --> 11:14.900
Ethical hacking with Python in 20 hours.

11:17.070 --> 11:17.560
Oxley.

11:18.720 --> 11:21.870
Oxley courses that append and we will make.

11:22.020 --> 11:24.270
It's actually right.

11:26.820 --> 11:27.900
Designing.

11:29.490 --> 11:35.040
Database models with my SQL.

11:35.770 --> 11:36.600
That's it.

11:36.610 --> 11:40.390
Now we will write print this down.

11:42.090 --> 11:42.630
Here.

11:43.020 --> 11:44.130
Let's print.

11:45.350 --> 11:47.960
Oxer the courses and one.

11:48.870 --> 11:51.410
Best courses in the world, best Python courses in the world.

11:51.420 --> 11:52.830
This is the first year.

11:53.010 --> 11:56.550
So actually this number is zero one.

11:57.410 --> 11:57.840
Two.

11:58.280 --> 11:58.790
Three.

12:03.630 --> 12:09.300
Now we will write zero under coding training in 33 hours.

12:09.510 --> 12:12.330
One Python course in the world.

12:12.750 --> 12:22.860
Two Ethical hacking with Python and 20 hours three designing database models with MySQL.

12:22.890 --> 12:30.990
So building list this way is very common because you often want to know the data your users want to

12:30.990 --> 12:33.630
store in a program until after the program is running, right?

12:33.630 --> 12:42.510
So to put your users in control, start by defining an empty list that still hold the user's value.

12:42.510 --> 12:46.800
Then append each new value provided to the list you just created here.
