WEBVTT

00:00.610 --> 00:03.070
Hello, my name is Stefan from Oxford Academy.

00:03.070 --> 00:06.160
And in this section you will learn about lists.

00:06.190 --> 00:11.030
What lists are and how to start working with the elements in a list.

00:11.050 --> 00:18.190
So let's allow you to store sets of information in one place, whether you have just a few items or

00:18.190 --> 00:19.600
millions of items.

00:19.600 --> 00:29.860
So lists are one of the python's most powerful features, readily accessible to new programmers, and

00:29.860 --> 00:33.700
they tie together many important concepts in programming.

00:33.700 --> 00:36.520
So what is a list?

00:36.700 --> 00:38.560
A list is a collection of items.

00:38.560 --> 00:39.880
In a particular order.

00:39.910 --> 00:46.390
You can make a list that includes the letter alphabets.

00:47.260 --> 00:48.600
Digits here.

00:48.730 --> 00:49.780
Letters.

00:50.690 --> 00:53.000
A, B or.

00:54.410 --> 00:57.770
A the C here ads here.

00:57.800 --> 01:01.840
You can create a list of numbers here.

01:01.850 --> 01:03.920
One two.

01:05.760 --> 01:08.100
Three, four.

01:08.840 --> 01:09.590
Five.

01:09.800 --> 01:11.300
You can also create.

01:14.350 --> 01:16.810
List of characters here.

01:19.690 --> 01:28.270
Which you will learn all of this in this section so you can put anything you want into list and the

01:28.270 --> 01:32.130
items in your list don't have to be related in a particular way, right?

01:32.140 --> 01:42.010
So because a list is usually contains more than one element, it's a good idea to make the name of your

01:42.010 --> 01:43.330
list plural.

01:43.330 --> 01:44.740
Such as?

01:45.250 --> 01:48.310
Uh, for example, instead of writing.

01:48.340 --> 01:49.120
Oh, sorry.

01:49.820 --> 01:54.530
So instead of writing your list variable name letter.

01:58.550 --> 02:06.320
You can write letters because it's a more good practice here.

02:06.320 --> 02:08.180
So in Python.

02:08.390 --> 02:10.100
Square braces.

02:10.100 --> 02:12.410
This square braces.

02:15.850 --> 02:23.080
Indicator list and individual elements in the list are separated by commas.

02:25.620 --> 02:28.640
Separated by commas.

02:28.680 --> 02:30.930
So let's actually create a.

02:31.970 --> 02:35.880
Example, a list that contains a few kinds of courses.

02:35.920 --> 02:36.500
Right?

02:36.500 --> 02:37.580
So.

02:38.840 --> 02:42.050
So course topics here.

02:42.080 --> 02:44.330
It's going to be here.

02:44.330 --> 02:47.450
We have braces, brackets.

02:47.450 --> 02:50.450
So now we're going to car.

02:50.480 --> 02:55.670
As you can see, we are getting an error because we we need to enter a strings car.

02:56.030 --> 02:57.200
So we use single quotes.

02:59.410 --> 03:00.190
Car.

03:00.520 --> 03:05.080
And here we will also add Android Kotlin.

03:05.410 --> 03:08.260
We will also add Java.

03:09.830 --> 03:10.670
Python.

03:14.040 --> 03:15.900
Digital forensics.

03:16.720 --> 03:20.230
Actually, let's decrease the font size a little bit maybe.

03:20.230 --> 03:20.740
Yeah.

03:20.770 --> 03:22.690
And digital fonts is okay for now.

03:22.720 --> 03:28.000
So after that we will print the course topics list.

03:28.390 --> 03:32.470
And as you can see here, this is the output.

03:32.650 --> 03:40.990
So if you ask a python, print the list that's Python retains its representation of a list, including

03:40.990 --> 03:42.910
the square braces here.

03:42.940 --> 03:48.670
So because this is the output you want to use, you want users to see.

03:48.700 --> 03:52.960
Let's learn how to access the individual items.

03:53.380 --> 04:01.660
For example, Car, Android, Kotlin, Java, Python and digital forensics.

04:01.900 --> 04:03.130
Let's try this now.

04:03.130 --> 04:12.400
So lists are ordered collections so you can access any element in a list by telling Python the position

04:12.400 --> 04:15.130
or index of the item desired.

04:15.160 --> 04:23.060
So to access an element in a list, write the name of the list followed by the end index of the item.

04:23.060 --> 04:25.520
So now there's an interesting thing I want to.

04:26.540 --> 04:26.890
Sorry.

04:27.350 --> 04:28.610
Firstly, it's actually get.

04:29.520 --> 04:36.110
And so in order to access this list, we will write, print or actually instead of print, we can also

04:36.110 --> 04:36.500
write.

04:36.530 --> 04:40.460
Yeah, we will write print inside this list.

04:40.460 --> 04:42.920
We will get course topics here.

04:43.580 --> 04:44.630
Course.

04:50.020 --> 04:50.860
Topics.

04:52.550 --> 04:54.350
And here we will use.

04:55.710 --> 04:56.420
Braces.

04:56.460 --> 04:58.260
Brackets like this.

04:58.380 --> 05:01.440
Let's actually use this different color so I can show you.

05:02.220 --> 05:02.620
Here.

05:04.220 --> 05:07.240
This is the braces.

05:07.250 --> 05:11.840
So here we will add the nth element.

05:11.840 --> 05:12.680
So.

05:14.080 --> 05:14.650
And.

05:16.310 --> 05:17.030
Element.

05:21.010 --> 05:21.870
From list.

05:28.450 --> 05:29.860
So in this case.

05:30.500 --> 05:34.550
For example, if we want to access the cars, the car is going to be zero.

05:34.910 --> 05:40.030
Android Kotlin is going to be remember, let's let's actually use different color.

05:40.130 --> 05:41.060
So.

05:41.970 --> 05:43.950
The car is going to be.

05:46.810 --> 05:47.680
Zero.

05:47.710 --> 05:52.110
Android Kotlin is going to be one.

05:52.120 --> 05:55.180
Java is going to be two.

05:55.450 --> 05:58.720
Python is going to be third element in the list.

06:00.490 --> 06:04.500
Digital forensics is going to be fourth element in the list.

06:04.510 --> 06:07.840
So if you want to access the cars, we will write zero.

06:07.840 --> 06:12.130
If you want to access the Android Kotlin, we will write one here.

06:12.340 --> 06:16.240
But if we want to access Java, we will write two.

06:16.270 --> 06:23.770
If we want to access Python, as you know, we will write three because the python is the third element

06:23.770 --> 06:24.490
of the list.

06:24.490 --> 06:28.990
So list starts from the zero one, 234.

06:29.320 --> 06:34.360
So if we want to access the digital forensics, we will write the fourth.

06:35.360 --> 06:36.080
So.

06:39.150 --> 06:43.500
So here we will write course, print course topics.

06:44.960 --> 06:45.350
Zero.

06:45.350 --> 06:46.940
And as you can see, it's a car.

06:48.120 --> 06:48.570
Android.

06:48.570 --> 06:49.320
Kotlin.

06:50.610 --> 06:51.210
Java.

06:52.380 --> 06:53.070
Python.

06:54.930 --> 07:01.230
Now python and let's five ops and let's actually try Python now.

07:01.810 --> 07:02.290
So.

07:03.290 --> 07:05.390
I feel Bradford is going to be digital forensics.

07:05.390 --> 07:09.210
As we know, as I showed you earlier in this lecture.

07:09.230 --> 07:12.870
One, two, three, four, five.

07:12.890 --> 07:13.330
Right.

07:13.340 --> 07:16.030
Fifth element of the list in this case.

07:16.040 --> 07:20.330
Zero, one, two, three, four from the index.

07:20.630 --> 07:28.160
So here, if you write 5 or 10, in this case, we don't have that range or that index.

07:28.160 --> 07:32.810
And as you can see, list index out of range because we don't have that much item.

07:33.500 --> 07:38.810
So this is the result you want to users to see in this case, for example, Java, right.

07:39.260 --> 07:41.720
So nearly formatted output.

07:41.720 --> 07:48.060
So you can also use the string methods from previous lectures on any element.

07:48.070 --> 07:53.330
This list, for example, course topics that we will write here.

07:53.450 --> 08:01.210
So we have l strip lower upper let's upper and here, as you can see, we have uppercase Java.

08:01.220 --> 08:06.050
So Python here considers the first item.

08:06.050 --> 08:12.560
Actually, let me let me I want to explain this later because most new programmers.

08:13.390 --> 08:16.660
Have problem with this index thing here.

08:16.660 --> 08:25.270
So Python considers the first item in a list to be at a position zero.

08:25.270 --> 08:28.180
In the end, most programming language is actually considered like this.

08:28.180 --> 08:33.520
So here the car is worth zero, right?

08:33.910 --> 08:34.780
Zero.

08:37.490 --> 08:41.420
And this is not the first car is a zero at the index.

08:41.420 --> 08:44.330
This is true of most programming languages.

08:44.330 --> 08:51.070
And the reason has to do with how the list operations are implemented at a lower level.

08:51.080 --> 08:54.740
So if you are receiving an unexpected results.

08:56.150 --> 09:01.640
Ask yourself if you are making a simple but common off by one error.

09:01.730 --> 09:07.190
So the second item in the list has an index of.

09:07.880 --> 09:09.530
One of.

09:11.540 --> 09:16.310
The second item in the list has an index of one.

09:19.740 --> 09:20.220
Here.

09:20.610 --> 09:22.190
So let's make this.

09:23.580 --> 09:25.380
And the third item.

09:26.940 --> 09:30.630
As an index of two again.

09:34.740 --> 09:35.970
The fourth item.

09:37.290 --> 09:38.430
As the index.

09:39.370 --> 09:40.840
Of three.

09:42.430 --> 09:47.200
And the fifth item has an index of four.

09:49.070 --> 09:49.770
That's it.

09:49.790 --> 09:53.360
So this code here.

09:54.480 --> 09:55.260
For example.

09:55.260 --> 09:56.130
Now let's.

09:57.890 --> 09:58.430
Here.

09:58.700 --> 09:59.630
So.

10:03.030 --> 10:05.850
Now we will print here.

10:07.340 --> 10:08.300
Zero.

10:12.280 --> 10:15.010
Let's actually copy this again and again.

10:18.800 --> 10:19.020
Four.

10:19.070 --> 10:19.550
Five.

10:20.400 --> 10:20.850
So.

10:21.120 --> 10:25.260
Zero one, two, three, four.

10:26.750 --> 10:29.930
And here, as you can see here, this is our output, right?

10:29.960 --> 10:37.160
The 012 here, zero goes to here.

10:38.180 --> 10:44.090
The one goes to here, the three goes to here, the second line index.

10:44.090 --> 10:47.300
Of course, the fourth index goes to here.

10:47.300 --> 10:52.910
And digital forensics, the last index fourth goes to here.

10:53.090 --> 11:03.230
So the python has a special syntax for accessing the last element in a list if you ask for them at indexed

11:03.260 --> 11:07.310
index Z minus negative one here.

11:07.310 --> 11:08.810
Let's let's try this.

11:10.340 --> 11:11.420
This is the weird, right?

11:11.690 --> 11:15.170
And as you can see here, negative one.

11:16.610 --> 11:26.120
If you ask for the item at the index negative one python will always returns the last item.

11:26.120 --> 11:31.280
Negative one returns negative one.

11:32.610 --> 11:33.870
Returns.

11:37.660 --> 11:38.860
Returns.

11:42.040 --> 11:44.020
Returns the last item.

11:53.040 --> 11:53.280
Yeah.

11:53.760 --> 12:02.940
So here the the code returns the digital forensics and this syntax is quite useful because you will

12:02.940 --> 12:07.950
often want to access the last items in a list without knowing exactly how long the list is.

12:07.950 --> 12:17.100
So the convention extend other negative index values as well, and the index minus two returns the second

12:17.100 --> 12:19.140
item from the end of the list.

12:19.620 --> 12:20.250
Yeah.

12:21.090 --> 12:28.260
And the index minus three returns the third item from the end and so forth.
