WEBVTT

00:00.200 --> 00:00.860
Hello guys.

00:00.860 --> 00:03.320
So we are going to continue our discussion with respect to Python.

00:03.320 --> 00:06.350
And now we are going to start data structures in Python.

00:06.350 --> 00:11.540
Some of the most common data structures that are used in Python programming language are like lists,

00:11.570 --> 00:13.310
tuples, sets and dictionaries.

00:13.310 --> 00:17.210
So in this series of videos, we are probably going to discuss about all these topics.

00:17.210 --> 00:19.820
In this video we are going to focus more on list.

00:20.090 --> 00:23.600
Uh, so let me just go ahead and show you what is the video outline.

00:23.600 --> 00:28.820
So first of all, we will, uh, go ahead and show you how to I will go ahead and show you how to create

00:28.820 --> 00:29.330
a list.

00:29.330 --> 00:35.270
Then I will also show you accessing list items, modifying list items, some of the amazing list methods

00:35.270 --> 00:36.110
that we use.

00:36.140 --> 00:38.960
Then we have operations like slicing list.

00:39.050 --> 00:41.510
How do I how do we iterate over list?

00:41.540 --> 00:43.220
You know by using for loop and all.

00:43.250 --> 00:46.580
Then along with that we'll also be seeing list comprehension.

00:46.580 --> 00:48.950
And then we will be seeing about nested list.

00:48.950 --> 00:52.100
All these things will be covered with lot of practical examples.

00:52.100 --> 00:55.610
And I'll also be talking about what are the common errors that we will be getting.

00:55.610 --> 01:00.390
So before I go ahead, first of all, let us go ahead and just see the definition of list.

01:00.390 --> 01:05.340
So here you can see list are ordered mutable collection of items right.

01:05.370 --> 01:07.170
Ordered mutable collection of items.

01:07.170 --> 01:09.570
What does mutable collection of items basically means?

01:09.720 --> 01:13.500
Like all the items that are present in list, we can actually change it.

01:13.530 --> 01:14.160
Okay.

01:14.280 --> 01:18.600
Um, and they can contain items of different data types also.

01:18.600 --> 01:18.870
Right.

01:18.870 --> 01:22.530
So these are the two main proper properties with respect to list.

01:22.590 --> 01:25.170
Uh, first of all, they are ordered mutable collection of items.

01:25.170 --> 01:28.410
And they can contain items of different different data types.

01:28.410 --> 01:30.480
So let me just go ahead and let me show you that.

01:30.510 --> 01:32.190
How do you define a list?

01:32.220 --> 01:34.710
Let's say I create a variable called as list.

01:34.920 --> 01:37.080
And if I use this two brackets.

01:37.080 --> 01:40.020
And before that don't forget to select a kernel.

01:40.020 --> 01:43.860
So right now I have selected the kernel based on the environment that I've actually created.

01:43.860 --> 01:49.980
So here you can see over here when I write list with some this empty square braces.

01:49.980 --> 01:57.930
And if I go ahead and print the type of this variable this will give us an empty list.

01:57.960 --> 01:58.260
Right.

01:58.260 --> 02:00.870
So this is a class type of list.

02:00.870 --> 02:03.450
So in order to create a list it is very much simple.

02:03.450 --> 02:06.720
You can just use this empty brackets right.

02:06.960 --> 02:12.600
Um now if I want to add elements in the list, uh, let's say that I want to go ahead and create it.

02:12.630 --> 02:15.210
Like I may have multiple names over here.

02:15.210 --> 02:23.940
Let's say I have Croatia, I have, um, Jack, I have Jacob.

02:23.940 --> 02:24.360
Right.

02:24.360 --> 02:26.640
So this is basically a list of names.

02:26.670 --> 02:27.150
Okay.

02:27.180 --> 02:33.180
I may also have other elements like I may have one, two, three, four, five, any number of elements.

02:33.180 --> 02:36.210
I may also have different different data types of elements over here.

02:36.240 --> 02:40.050
So here if I go ahead and go ahead and print names.

02:40.650 --> 02:44.310
So it is giving me a name error because I did not write names.

02:44.310 --> 02:47.700
So here you can see that I'm able to get a list of elements right.

02:47.700 --> 02:49.530
So this is how a list is.

02:49.560 --> 02:52.440
Let's say that I go ahead and create a mixed list.

02:52.470 --> 02:55.320
Mixed underscore list list.

02:55.320 --> 02:57.970
And here let's say my first is a number.

02:58.000 --> 03:00.310
Second is a string.

03:00.340 --> 03:02.770
Third is a floating point right.

03:02.770 --> 03:04.450
And fourth is a Boolean variable.

03:04.480 --> 03:04.900
Right.

03:04.930 --> 03:07.270
So I may define any types of data type.

03:07.270 --> 03:08.740
And I may also print this.

03:08.740 --> 03:12.730
So let me just go ahead and print mixed underscore list.

03:12.730 --> 03:16.750
So I hope you got an idea about how to probably create a list of items right.

03:16.780 --> 03:21.100
So one is directly we are using this particular empty brackets.

03:21.100 --> 03:23.920
Or you can also go ahead and add elements over here.

03:24.190 --> 03:28.930
Um with respect to and any, any kind of elements, any different different data types of elements you

03:28.930 --> 03:29.860
can basically add.

03:29.890 --> 03:30.370
Okay.

03:30.400 --> 03:36.550
Now let's talk about accessing accessing list items.

03:36.550 --> 03:39.550
How do we access the list elements.

03:39.580 --> 03:40.060
Right.

03:40.060 --> 03:43.630
So let's say that I uh I create a fruits right.

03:43.630 --> 03:47.590
Let's say that I'm going to create a fruits element like a list of fruits.

03:47.590 --> 03:49.270
Let's say like apple.

03:49.270 --> 03:51.610
It can be banana.

03:51.640 --> 04:00.620
It can be cherry It can be, um, Kiwi.

04:00.860 --> 04:06.350
It can be, um, pomegranate.

04:06.380 --> 04:06.980
Okay.

04:07.520 --> 04:10.010
Or let me just write a simple, uh.

04:10.040 --> 04:10.340
Okay.

04:10.340 --> 04:11.570
Let's go ahead and see.

04:11.570 --> 04:13.340
Uh, cherry is already written.

04:13.550 --> 04:14.540
Um, Apple.

04:14.570 --> 04:15.440
Banana, cherry.

04:15.710 --> 04:16.370
Kiwi.

04:16.880 --> 04:17.840
Um, okay.

04:17.840 --> 04:20.570
I, I'm not able to remember more fruits names.

04:20.570 --> 04:21.140
Right.

04:21.320 --> 04:23.930
So let's just keep it till here, okay.

04:24.230 --> 04:24.590
Or.

04:24.590 --> 04:25.520
Okay, fine.

04:25.550 --> 04:27.770
I finally I got one guava.

04:27.770 --> 04:28.430
Right.

04:28.430 --> 04:31.550
So I'm just going to go ahead and create this list of elements.

04:31.550 --> 04:33.800
So here is my list of elements over here.

04:33.830 --> 04:38.240
Now uh, let's say that I want to go ahead and display Apple right.

04:38.240 --> 04:42.860
So in order to display it all I have to do is that just go ahead and right roots fruits.

04:42.860 --> 04:46.520
And here you can probably see that I can actually use indexing.

04:46.550 --> 04:46.970
Right.

04:46.970 --> 04:50.990
So whenever we create the elements inside a list okay.

04:50.990 --> 04:56.610
So here this first fruit is basically present in the zeroth index, then this is present in the first

04:56.610 --> 04:56.910
index.

04:56.910 --> 04:57.480
Second index.

04:57.480 --> 04:58.020
Third index.

04:58.020 --> 04:58.770
Fourth index.

04:58.770 --> 05:04.530
So similarly all the indexes uh, when I probably say all the indexes in Python starts with zero.

05:04.560 --> 05:09.150
If you know about R programming language, all the indexes over there starts with one number one.

05:09.150 --> 05:09.450
Right.

05:09.450 --> 05:14.130
But here we are specifically going to use um zero is the index over here.

05:14.160 --> 05:14.550
Right.

05:14.550 --> 05:18.300
But uh if I really want to just display Apple right.

05:18.300 --> 05:21.090
So I will just go ahead and write fruit of zero.

05:21.090 --> 05:21.390
Right.

05:21.390 --> 05:23.400
If I'm actually trying to print this.

05:23.400 --> 05:26.310
So let me just go ahead and write print Fruits of zero.

05:26.310 --> 05:28.170
It is not nothing but apple.

05:28.170 --> 05:33.720
Let's say I want to probably get fruit of uh, um in middle cherry.

05:33.750 --> 05:34.020
Right.

05:34.050 --> 05:35.730
So this will become 012.

05:35.760 --> 05:39.960
So if I go ahead and write fruits of two.

05:39.990 --> 05:42.090
So I will be able to get apple and cherry.

05:42.090 --> 05:45.960
And there are some amazing techniques with respect to indexing also.

05:45.960 --> 05:48.750
So let's say that I want to pick up guava right.

05:48.750 --> 05:50.970
So I can also go ahead and write print.

05:51.240 --> 05:51.900
Um, yeah.

05:51.930 --> 05:55.710
One way is that I can go ahead and take one zero, one two, three four.

05:55.710 --> 05:59.550
So I can probably go ahead and write fruits of fourth index.

05:59.550 --> 06:00.810
I will be able to get guava.

06:00.840 --> 06:04.380
Now this guava can also be taken through a different way.

06:04.380 --> 06:05.700
So let me just go ahead and write.

06:05.700 --> 06:10.020
So let's say that I'm going to write print of all fruits.

06:10.590 --> 06:14.520
Let me just say and show it to you over here.

06:14.520 --> 06:20.340
So let me just go ahead and write fruits of Fruits of okay.

06:20.340 --> 06:23.160
And now in this particular case let me just go ahead and write minus one.

06:23.160 --> 06:24.000
Let's see what will happen.

06:24.030 --> 06:27.750
See minus one is nothing, but it is basically talking about the last element itself.

06:27.750 --> 06:28.020
Right.

06:28.020 --> 06:30.210
So I think I should be able to get both guava.

06:30.240 --> 06:30.690
Right.

06:30.690 --> 06:34.050
So this is the amazing thing with respect to fruits, right.

06:34.140 --> 06:34.920
Uh, sorry.

06:34.920 --> 06:35.850
This list.

06:35.880 --> 06:36.180
Right.

06:36.180 --> 06:41.790
You are able to probably retrieve any fruit or any items inside this list just by using simple indexing.

06:41.820 --> 06:47.460
Okay, now let me just show you one more way of printing some set of fruits elements.

06:47.460 --> 06:49.950
So if I go ahead and write fruits okay.

06:49.950 --> 06:55.990
And you know, if I just use the index one okay, I'll be able to get banana.

06:55.990 --> 06:58.870
So I'm getting banana zero one I'm getting banana over here.

06:58.870 --> 07:00.580
But what if I have a requirement?

07:00.580 --> 07:03.310
I need to get all the elements from banana till guava.

07:03.340 --> 07:03.820
Right.

07:03.820 --> 07:08.320
So if I go ahead and just make one simple change over here, right.

07:08.350 --> 07:11.590
What I will do, I'll say write fruits one colon.

07:11.590 --> 07:11.950
Right?

07:11.950 --> 07:18.310
One colon basically means from one first index till the end index because I'm not giving anything after

07:18.310 --> 07:18.820
the colon.

07:18.820 --> 07:23.950
So if I just go ahead and execute this here you can see banana cherry kiwi guava right.

07:23.950 --> 07:26.470
So this is one way right now let me do one thing.

07:26.500 --> 07:31.630
Let me just go ahead and print fruits one colon.

07:31.630 --> 07:36.040
And let's say I want to get all the elements till this kiwi index one.

07:36.190 --> 07:37.870
So here you have zero one.

07:37.870 --> 07:39.370
So right two three.

07:39.400 --> 07:39.610
Right.

07:39.640 --> 07:43.930
So now if I go ahead and write one colon three, that basically means it is just going to pick up this

07:43.930 --> 07:44.410
first index.

07:44.410 --> 07:46.720
Second index it is not going to pick up the Kiwi index.

07:46.720 --> 07:47.230
Right.

07:47.500 --> 07:49.670
Uh and now if I go ahead and display it.

07:49.670 --> 07:51.590
So here you can see banana and cherries there.

07:51.620 --> 07:56.090
That basically means the third index is not getting picked up till the third index everything will get

07:56.090 --> 07:56.990
picked up right.

07:57.020 --> 08:01.580
So if I don't write any element over here, so it is just going to take it completely till the end.

08:01.610 --> 08:02.180
Right.

08:02.180 --> 08:07.490
And uh, here also what I can actually do, let me just go ahead and show you one more thing.

08:07.490 --> 08:12.260
So if I go ahead and write print of fruits, uh, minus one colon.

08:12.290 --> 08:12.620
Right.

08:12.650 --> 08:17.480
Now, if I go ahead and execute this, you can see minus one colon basically means from minus one element

08:17.510 --> 08:18.260
till colon.

08:18.260 --> 08:18.470
Right.

08:18.500 --> 08:19.850
Till colon means till the end.

08:19.850 --> 08:22.580
And this is just my last element over there okay.

08:22.580 --> 08:28.670
But if I just go ahead and write -1 or 2 let's say second index.

08:28.670 --> 08:35.450
So here I can see that you have to please observe over here minus one is nothing but this specific element

08:35.450 --> 08:35.930
right.

08:35.960 --> 08:38.000
Two is this right.

08:38.000 --> 08:40.100
But I'm not talking about all these elements.

08:40.130 --> 08:44.900
Now if I go ahead and write minus one to -3 or -3 right.

08:44.930 --> 08:50.730
Now here also you'll be able to see this indexing Thing is obviously a little bit confusion.

08:50.730 --> 08:51.120
Okay.

08:51.150 --> 08:55.320
There is a little bit of confusion over here because when I'm picking up the minus one element, this

08:55.320 --> 08:56.310
is it is giving us.

08:56.310 --> 08:58.530
But I'm saying from -1 to -3.

08:58.560 --> 08:58.920
Right.

08:58.920 --> 09:00.360
So there is no such element.

09:00.360 --> 09:04.440
And we'll talk more about this kind of examples and how to do this kind of indexing.

09:04.440 --> 09:07.800
Also when we are further discussing about many things as such.

09:07.830 --> 09:08.130
Right.

09:08.160 --> 09:09.720
Right now don't worry about this.

09:09.720 --> 09:11.760
Otherwise you'll get more confused over here.

09:11.910 --> 09:13.950
Uh, I'll just keep it like this.

09:13.950 --> 09:18.930
I'll remove this particular code for some time, and then later on when you'll see in the series of

09:18.930 --> 09:21.330
videos, we'll also be talking about those kind of indexing.

09:21.360 --> 09:21.840
Okay.

09:21.870 --> 09:22.980
Now perfect.

09:23.010 --> 09:23.490
Till here.

09:23.490 --> 09:26.910
I think uh, we have, uh, learnt many things over here.

09:26.940 --> 09:30.600
Now, what I will be showing you is that how you can modify the list elements.

09:30.630 --> 09:31.050
Okay.

09:31.050 --> 09:36.900
So let me just go ahead here and show you modifying the list elements okay.

09:36.930 --> 09:39.960
Now modifying the list elements is very simple.

09:39.960 --> 09:42.690
Let's say that I want this is my fruits right.

09:42.690 --> 09:43.950
So this is my fruits.

09:43.950 --> 09:47.190
I want to make sure that I replace banana with something else.

09:47.220 --> 09:48.210
Right now.

09:48.210 --> 09:48.720
Banana.

09:48.750 --> 09:49.620
You know it.

09:49.620 --> 09:50.910
It is in first index.

09:50.940 --> 09:51.120
Right.

09:51.120 --> 09:53.430
So if I go ahead and write this it is in first index.

09:53.430 --> 09:57.960
Let's say from this I want to probably change this into watermelon okay.

09:58.320 --> 10:01.920
And now I will just go ahead and print my fruits.

10:01.950 --> 10:02.430
Right.

10:02.430 --> 10:07.260
So in that specific index I am writing watermelon over here and I'm actually displaying it.

10:07.260 --> 10:12.330
Now you can see my fruits has changed banana to uh to watermelon right.

10:12.330 --> 10:18.840
So this way in the indexing also you can directly go ahead and probably replace this particular values.

10:18.840 --> 10:19.230
Right.

10:19.230 --> 10:24.270
So this is how you modify uh any elements that is present over here.

10:24.300 --> 10:27.990
Not only that, let's say I want to go ahead and write like this.

10:27.990 --> 10:30.150
Fruits okay.

10:30.180 --> 10:32.640
Fruits one colon okay.

10:32.640 --> 10:34.830
So one colon is basically giving you this answer.

10:34.860 --> 10:39.300
Now if I go ahead and just write here, please replace everything with watermelon.

10:39.330 --> 10:41.490
Now if I go ahead and see fruits.

10:41.640 --> 10:45.790
So here you can see uh I'm getting this error or.

10:45.820 --> 10:47.560
Let's see what is the problem.

10:47.710 --> 10:48.940
Watermelon okay.

10:48.970 --> 10:54.040
Now what it has done is that from this particular index, from this particular index it has replaced

10:54.070 --> 10:55.810
with this particular word.

10:55.840 --> 10:56.290
Right.

10:56.290 --> 10:59.050
But here it is not considered as a word.

10:59.050 --> 11:01.660
Instead it is taking this as character by character.

11:01.690 --> 11:05.020
We will also be seeing how we can add word to word.

11:05.050 --> 11:05.470
Right.

11:05.470 --> 11:10.060
So in in in in list you have some amazing methods like append and all.

11:10.060 --> 11:12.730
We will be talking about it as we go ahead right now okay.

11:12.760 --> 11:14.620
Just after this section itself.

11:14.650 --> 11:14.950
Right.

11:14.950 --> 11:17.710
So this is one of the problem that we see right now.

11:17.710 --> 11:18.550
Let me do one thing.

11:18.550 --> 11:22.900
Let me again use that same fruits over here that I've actually defined.

11:23.080 --> 11:23.560
Okay.

11:23.560 --> 11:25.090
But you understood the problem.

11:25.090 --> 11:27.940
What has happened over here as soon as I said one colon.

11:27.970 --> 11:28.180
Right.

11:28.210 --> 11:31.900
So from first index it has just added w a t r.

11:31.930 --> 11:34.630
So it is not just considered this as a single word.

11:34.630 --> 11:37.450
Instead it is considering character by character and it is adding it.

11:37.450 --> 11:40.060
Okay, so let me just go ahead and define my fruits again.

11:40.090 --> 11:40.540
Okay.

11:40.570 --> 11:47.280
Now let me just go ahead and discuss more about amazing thing that is called as list methods.

11:47.310 --> 11:50.910
Okay, now this list methods is quite beautiful.

11:50.910 --> 11:53.610
We will see to it and we'll be learning more about it.

11:53.640 --> 11:56.730
Okay, now let's say I want to, as I said right.

11:56.730 --> 12:02.070
I want to append an element inside this okay I want to add one element at the end let's say.

12:02.070 --> 12:05.400
So for this I will go ahead and write fruits dot append.

12:05.400 --> 12:09.030
And here let's say I want to append orange okay.

12:09.090 --> 12:16.500
Now once I write that basically means this will add an item okay to the end okay.

12:16.770 --> 12:19.620
It will basically add an item to the end okay.

12:19.650 --> 12:25.320
And if I just go ahead and print my fruits you will be able to see this.

12:25.320 --> 12:25.680
Right.

12:25.680 --> 12:31.260
So now here we'll be able to see apple banana cherry kiwi guava and oranges over here.

12:31.290 --> 12:31.830
Right.

12:32.430 --> 12:39.330
Now let's say that I have a requirement that I want to probably append any element at a specific index.

12:39.360 --> 12:39.780
Okay.

12:39.810 --> 12:49.200
So let's say I want to add, um, let's say I want to add watermelon in this first index.

12:49.800 --> 12:50.010
Okay.

12:50.010 --> 12:51.930
And right now in the first index banana is there.

12:51.930 --> 12:57.210
So what I will do I'll say fruits dot insert okay insert.

12:57.330 --> 12:59.100
And I will give the index number.

12:59.130 --> 13:00.870
The first element will be the index number.

13:00.870 --> 13:05.760
And the second element will be whatever item I want to put let's say banana okay.

13:05.760 --> 13:09.150
And then I'm just going to print fruits.

13:10.500 --> 13:13.350
So here you can see apple banana banana okay.

13:13.380 --> 13:15.300
Banana was already there I guess.

13:15.480 --> 13:16.920
Yeah banana was there.

13:16.920 --> 13:18.150
Let me do one thing.

13:18.150 --> 13:21.390
Let me add watermelon also.

13:21.420 --> 13:21.630
Okay.

13:21.660 --> 13:24.300
So in the first index I'm just going to add watermelon.

13:24.300 --> 13:29.520
So here you can see apple watermelon banana banana banana because I have added one time right.

13:29.550 --> 13:31.830
Let's say that I hate two bananas are there.

13:31.830 --> 13:32.820
I want to remove this.

13:32.820 --> 13:35.400
So I will go ahead and write fruits dot remove.

13:35.400 --> 13:39.150
So remove is another inbuilt function uh that is present inside this.

13:39.150 --> 13:40.620
So here I'm going to basically write right.

13:40.650 --> 13:41.280
Banana.

13:41.400 --> 13:41.820
Okay.

13:41.850 --> 13:45.570
And now if I go ahead and print fruits.

13:45.600 --> 13:46.020
Okay.

13:46.050 --> 13:48.840
So here you can see banana has gone right now.

13:48.840 --> 13:51.000
But we don't have one more additional banana.

13:51.030 --> 13:51.810
Okay.

13:52.320 --> 14:03.330
Uh, let's say I want to also remove and, um, let's say, uh, see, whenever we are using this remove.

14:03.360 --> 14:03.750
Right.

14:03.750 --> 14:13.500
It is basically removing the first occurrence of an item.

14:13.530 --> 14:14.220
Right.

14:14.520 --> 14:19.140
Now let's say I want to remove and return the last item.

14:20.640 --> 14:22.860
Return the last item.

14:24.360 --> 14:24.960
Okay.

14:26.430 --> 14:28.350
Let's say I want to do this.

14:28.650 --> 14:30.660
Uh, what do I mean by this?

14:30.660 --> 14:35.070
Let's say I go ahead and use one amazing inbuilt function which is called as pop.

14:35.100 --> 14:35.670
Okay.

14:35.820 --> 14:42.340
Now pop basically means it is just going to pop the last element that is present in that particular

14:42.340 --> 14:44.800
fruit, and it is going to return us.

14:44.830 --> 14:45.010
Right.

14:45.040 --> 14:49.630
So here I'm going to write popped underscore fruit okay.

14:49.660 --> 14:50.560
Is equal to.

14:50.590 --> 14:52.840
And let me just go ahead and print it.

14:52.840 --> 14:54.580
So I'm going to print it over here.

14:54.580 --> 14:58.000
And let me just go ahead and write pop fruits okay.

14:58.030 --> 15:00.820
And uh let me just print it okay.

15:00.850 --> 15:07.210
Let's uh because at the end of the day, once, I probably, uh, print this and I'll also print the

15:07.210 --> 15:09.610
remaining items that are there in the fruits.

15:09.940 --> 15:10.390
Okay.

15:10.420 --> 15:12.520
So here you can see orange has been popped.

15:12.520 --> 15:12.880
Why?

15:12.910 --> 15:16.870
Because the last element in this list of fruits was orange.

15:16.870 --> 15:20.470
When orange was popped from this particular orange got removed.

15:20.500 --> 15:23.620
Okay, remove and return the last element.

15:24.040 --> 15:25.840
That is how you can specifically do it.

15:25.840 --> 15:28.600
And for that we use an inbuilt function called as pop.

15:28.630 --> 15:36.190
Okay, now let's say that I want to get an index of any fruit right based on the name of the fruit.

15:36.190 --> 15:39.410
So if I go ahead and write fruits dot index.

15:39.410 --> 15:43.460
And here let's say that I want to use cherry.

15:43.730 --> 15:48.800
I want to get the index of the fruit called as cherry okay cherry.

15:48.830 --> 15:51.290
And this will basically be my index.

15:52.400 --> 15:55.700
And let me just go ahead and print the index.

15:57.020 --> 16:02.930
Now if I go ahead and execute, you can see that cherry is basically present in 012 three third index.

16:02.930 --> 16:04.820
So I am able to get the output.

16:04.850 --> 16:05.390
Okay.

16:05.840 --> 16:13.160
Uh, again one more thing is that let me just go ahead and do one thing fruit dot append or I will try

16:13.190 --> 16:16.790
to insert in the second index.

16:16.970 --> 16:18.590
Banana okay.

16:19.100 --> 16:20.690
Banana is already there.

16:20.720 --> 16:24.320
And now let me do one one more inbuilt function.

16:24.320 --> 16:26.660
I will just go ahead and write fruit dot count.

16:26.810 --> 16:28.820
And here I will just go ahead and write.

16:28.850 --> 16:30.380
Sorry, it should be count.

16:30.470 --> 16:34.400
I will just go ahead and write banana okay.

16:34.610 --> 16:37.470
And let me just print this.

16:37.500 --> 16:38.070
Okay.

16:38.640 --> 16:43.860
Now, what is going to happen is that you'll be able to see it'll just count the number of elements.

16:43.860 --> 16:50.100
And obviously, after inserting this banana right now, if you see inside my fruits there are two bananas,

16:50.100 --> 16:50.340
right?

16:50.430 --> 16:51.600
Banana and banana.

16:51.600 --> 16:52.890
So it is just counting that.

16:52.890 --> 16:57.300
How many number of items this specific uh, in this particular list it is there.

16:57.330 --> 16:57.900
Right.

16:58.290 --> 17:04.260
So here I'm just showing you different, different inbuilt function just by using a list of items.

17:04.260 --> 17:08.370
And here you can see I've shown you a lot of coding with respect to this okay.

17:08.910 --> 17:11.370
Now I may also do something like this.

17:11.370 --> 17:13.440
I may sort this entire list of items.

17:13.440 --> 17:16.230
So if I go ahead and write fruits dot sort.

17:16.980 --> 17:18.600
So here you'll be able to see.

17:18.630 --> 17:23.100
Now if I go ahead and print this fruits you'll be seeing apple banana.

17:23.130 --> 17:23.490
Banana.

17:23.490 --> 17:23.820
Cherry.

17:23.850 --> 17:24.180
Guava.

17:24.210 --> 17:24.510
Kiwi.

17:24.600 --> 17:25.380
Watermelon.

17:26.040 --> 17:36.690
So automatically based on so in in short this will this will sort the list in ascending order.

17:37.020 --> 17:37.410
Okay.

17:37.440 --> 17:39.930
It is just going to sort all the lists in ascending order.

17:39.960 --> 17:42.780
And finally here you have fruits dot reverse.

17:42.810 --> 17:46.860
Reverse is another function which will reverse all the elements over here.

17:46.890 --> 17:52.290
Now if I go ahead and do this right now you can see the all the list of the elements will basically

17:52.290 --> 17:53.430
get reversed right.

17:53.460 --> 17:59.310
So this is nothing, but it reverses the list okay.

17:59.370 --> 18:04.770
And just I'm showing you what all different different inbuilt functions are basically present over here.

18:04.800 --> 18:05.310
Okay.

18:05.310 --> 18:11.760
And then finally if I want to clear the entire list I can go ahead and write fruits dot clear.

18:12.000 --> 18:12.450
Right.

18:12.480 --> 18:15.570
And now if I use this inbuilt function.

18:15.570 --> 18:22.770
So this will remove all items from the list okay.

18:22.800 --> 18:25.530
Now if I go ahead and print fruits.

18:26.460 --> 18:29.040
So here you can see I'm getting an empty list.

18:29.040 --> 18:34.580
So till now we have discussed about mainly uh if, if I go ahead and show you with respect to the video,

18:35.630 --> 18:40.100
we have understood about creating list, accessing list items, modifying list elements.

18:40.370 --> 18:42.230
Uh, then we discussed about list methods.

18:42.230 --> 18:44.780
Now we are going to discuss about slicing list.

18:44.780 --> 18:48.170
So let's go ahead and discuss more about slicing list.

18:50.390 --> 18:53.630
So guys now let's go ahead and talk more about slicing list.

18:53.630 --> 18:57.050
So before that I will go ahead and make some cells.

18:57.050 --> 18:58.880
Uh so there is a shortcut.

18:58.880 --> 19:04.100
Just press escape and a you will be able to create as many number of cells as you want.

19:04.130 --> 19:04.610
Okay.

19:04.640 --> 19:10.340
Now what I'm actually going to do is that I am just going to take this numbers.

19:10.370 --> 19:10.580
Okay.

19:10.580 --> 19:14.300
So I'm defining these numbers 123456789 ten.

19:14.300 --> 19:17.900
Now I will just go ahead and write some print elements.

19:17.900 --> 19:23.360
Let's say print numbers two colon five okay.

19:23.690 --> 19:28.550
Now let's talk about more numbers.

19:30.140 --> 19:30.860
Oops.

19:34.490 --> 19:35.750
Colon five.

19:35.780 --> 19:37.730
Okay, okay.

19:37.730 --> 19:41.390
I didn't close this brackets, so that is the reason it was giving me an error.

19:41.420 --> 19:42.530
No worries.

19:43.580 --> 19:48.620
Now I will go ahead and write print numbers five colon.

19:48.770 --> 19:54.260
And along with this we will also go ahead and see print numbers.

19:55.700 --> 19:57.320
Double colon two.

19:57.350 --> 19:57.950
Okay.

19:58.670 --> 19:59.750
Double colon.

19:59.750 --> 20:01.640
So here we are also learning about double colon.

20:01.670 --> 20:03.950
Single colon I have just given you an idea about it.

20:03.950 --> 20:05.930
But we'll also see with respect to double colon.

20:05.930 --> 20:10.130
And then we'll also go ahead and print our numbers.

20:11.420 --> 20:13.850
Double colon minus one.

20:13.880 --> 20:14.390
Okay.

20:14.420 --> 20:21.560
Now just pause for a second and just try to imagine in your mind like what will be the specific outputs

20:21.590 --> 20:22.100
okay.

20:22.100 --> 20:23.840
And then we will discuss further.

20:23.870 --> 20:24.410
Okay.

20:24.440 --> 20:26.390
So here you can see two colon five.

20:26.420 --> 20:35.450
It is very simple 012 from 2 to 5 elements of Three, four, five is basically getting displayed 012345.

20:35.450 --> 20:37.340
So this three elements will get displayed.

20:37.370 --> 20:40.310
Colon 512345 will get displayed.

20:40.310 --> 20:42.590
So it is basically coming over here till five.

20:42.620 --> 20:46.970
Then you have 6789 from five colon to till the end.

20:47.000 --> 20:48.680
Now this is very much important.

20:48.680 --> 20:49.820
Double colon two.

20:49.850 --> 20:51.200
What does this basically mean.

20:51.200 --> 20:55.250
And double colon two basically means from all the elements from first.

20:55.700 --> 20:58.580
And this two will be taken as a step size.

20:58.610 --> 20:58.880
Right.

20:58.910 --> 21:01.040
So we will jump two steps ahead.

21:01.040 --> 21:04.430
Like from here we will jump one two then three will get displayed again.

21:04.430 --> 21:07.010
Jump two steps five will be displayed from again.

21:07.010 --> 21:10.010
From this jump to two steps seven will get displayed again.

21:10.010 --> 21:10.880
Jump over here.

21:10.910 --> 21:12.380
Nine will be getting displayed.

21:12.380 --> 21:13.700
So double colon.

21:13.730 --> 21:16.160
See if I really want to make you understand about double colon.

21:16.160 --> 21:18.080
So I will go ahead and write double colon.

21:18.110 --> 21:19.970
Double colon basically means all the elements.

21:20.000 --> 21:23.750
Right now if I am writing okay fine.

21:23.780 --> 21:26.150
Uh let's give the step size as one.

21:26.150 --> 21:26.390
Then.

21:26.390 --> 21:31.450
Also I'll be getting the same output if I give the step size to two, so double jumps will be happening,

21:31.480 --> 21:31.930
right?

21:31.960 --> 21:33.490
This is basically the step size.

21:33.490 --> 21:40.120
Then if I write three then again three steps like from here one two, jump and third whichever will

21:40.150 --> 21:41.350
be the element that will get displayed.

21:41.350 --> 21:42.790
So four 710 right.

21:42.820 --> 21:44.980
So I hope you got an idea about it.

21:45.010 --> 21:46.990
Now double colon one basically means what.

21:47.020 --> 21:47.410
Okay.

21:47.410 --> 21:49.120
So double colon one.

21:49.120 --> 21:50.110
Double colon is nothing.

21:50.110 --> 21:52.330
But it is all the elements minus one okay.

21:52.360 --> 21:55.480
From previous take all the elements one by one and display it.

21:55.510 --> 21:58.300
If I go ahead and again write something like this.

21:58.300 --> 22:01.180
Let's say I go ahead and write numbers okay.

22:01.210 --> 22:03.400
Double colon minus two.

22:03.430 --> 22:06.160
Write some from back every two numbers.

22:06.160 --> 22:06.430
Right.

22:06.460 --> 22:09.670
It will skip every one number and display the other number over here.

22:09.700 --> 22:10.120
Right.

22:10.120 --> 22:12.250
So this is basically called as a slicing.

22:12.250 --> 22:15.820
And uh some of the operations will be involved in slicing.

22:15.820 --> 22:21.250
Whenever we want to retrieve some results we want to modify them, do something right so we can actually

22:21.250 --> 22:21.820
use it.

22:21.850 --> 22:22.240
Right.

22:22.270 --> 22:31.060
Now coming to the next thing is iterating over list Okay, now I've already shown you how to iterate

22:31.060 --> 22:31.900
over strings.

22:31.900 --> 22:35.110
Similarly, you can also iterate over a list, right?

22:35.110 --> 22:38.410
So for that also again I will be going and using for loop.

22:38.410 --> 22:43.420
Let's say I will go ahead and write for fruit for fruit in fruits.

22:43.450 --> 22:44.020
Right.

22:44.020 --> 22:48.820
And I will just go ahead and inside and print all the fruit items that I have.

22:49.090 --> 22:49.480
Right.

22:49.510 --> 22:53.500
So here one by one right now no fruit items is present or what.

22:53.920 --> 22:55.780
Okay, okay I have cleared that fruits.

22:55.780 --> 22:56.230
Right.

22:56.260 --> 22:57.340
So let me do one thing.

22:57.340 --> 23:02.170
Let me just take numbers over here so that I will be able to see through it.

23:02.200 --> 23:02.560
Right.

23:02.590 --> 23:05.800
For number in numbers.

23:05.800 --> 23:06.340
Right.

23:06.340 --> 23:08.530
So numbers is also a collection over here.

23:08.530 --> 23:10.150
List of collection list of elements.

23:10.150 --> 23:13.150
So 123456789 ten okay.

23:13.180 --> 23:14.320
So this is also there.

23:14.350 --> 23:18.970
Let's say I want to iterate all this list with indexes also.

23:19.450 --> 23:24.940
So I want to iterate iterating with index.

23:24.940 --> 23:31.160
So for this I can use for index, comma, fruit, fruit or index.

23:31.160 --> 23:34.460
Sorry for index comma number in numbers.

23:34.490 --> 23:37.160
Now once I use this numbers right.

23:37.190 --> 23:39.140
Obviously see if I'm directly using this number.

23:39.140 --> 23:42.260
I know this is a list but if I want index information.

23:42.260 --> 23:47.000
Also I have an inbuilt function in Python which is called as enumerate okay.

23:47.000 --> 23:52.220
And if we specifically use this enumerate that basically means we are also going to get the index number.

23:52.220 --> 23:58.010
So if I go ahead and print index comma number now you'll be able to see all the indexes.

23:58.010 --> 23:59.480
So this is my zeroth index.

23:59.480 --> 24:01.490
The first element is present in the zeroth index.

24:01.550 --> 24:06.020
Then I have two which is present in the first index then three in the second index, four in the third

24:06.020 --> 24:11.480
index, five in the fourth index, six in the fifth index, seven in the sixth index, eighth in the

24:11.480 --> 24:15.110
seventh index, nine in the eighth index, and ten in the ninth index.

24:15.110 --> 24:16.550
So I have all these things.

24:16.550 --> 24:21.830
And just by using this inbuilt function, you get an access of the index number also along with the

24:21.830 --> 24:24.380
list of elements that are present in that particular list.

24:24.410 --> 24:24.920
Okay.

24:24.920 --> 24:30.440
so this is one amazing thing about, uh, you know, you can also iterate over the list.

24:30.470 --> 24:32.540
You can also iterate along with the index.

24:32.570 --> 24:33.020
Right.

24:33.050 --> 24:39.890
Now let's go ahead and talk about one more amazing thing, which is basically called as list comprehension.

24:39.920 --> 24:40.490
Okay.

24:41.030 --> 24:43.220
Now list comprehension.

24:43.250 --> 24:47.450
Now guys let's let's consider that, uh, I want to do something right.

24:47.450 --> 24:55.940
I want to probably, uh, let's say I'll write a for loop for x in range for x in range.

24:56.000 --> 24:58.010
Let's say I'm going to write ten.

24:58.370 --> 25:04.430
And here, uh, what I'm actually going to do is that I'm going to probably create a list element.

25:04.430 --> 25:07.220
Let's say I'm going to create a list empty elements.

25:07.220 --> 25:10.460
And then I will go ahead and write list dot append.

25:10.850 --> 25:13.010
And let me just go ahead and do this.

25:13.040 --> 25:13.610
Okay.

25:13.610 --> 25:15.650
So just imagine what I've actually done.

25:16.010 --> 25:21.230
Uh, here inside this for loop I'm squaring every number and I'm appending in this particular list.

25:21.260 --> 25:21.530
Right.

25:21.530 --> 25:24.720
And finally I can go ahead and print this particular list.

25:24.750 --> 25:25.110
Okay.

25:25.140 --> 25:30.810
So in short, this is a code that I've actually written to square every numbers inside this particular

25:30.810 --> 25:31.920
range of numbers.

25:31.950 --> 25:32.280
Right.

25:32.280 --> 25:37.320
So I'm getting 01249 1625 3649, 64, 81.

25:37.350 --> 25:39.480
Now see imagine in this line of code.

25:39.510 --> 25:39.750
Right?

25:39.750 --> 25:41.790
I've written 3 to 4 lines right over here.

25:42.000 --> 25:43.890
First of all, initialized an empty list.

25:43.920 --> 25:45.510
Then I'm putting a for loop.

25:45.510 --> 25:47.760
Then I'm performing this specific operation.

25:47.760 --> 25:51.270
What if I can perform this entire list operation?

25:51.270 --> 25:55.320
Because everything is happening inside a list itself, and we are creating a new list also over here.

25:55.350 --> 25:55.950
Right?

25:55.980 --> 25:59.850
Obviously, if you're creating your list again, new list over here, again, playing with different

25:59.850 --> 26:01.890
different elements, more memory will be required.

26:01.920 --> 26:06.420
So Python actually helps us to play with list comprehension.

26:06.450 --> 26:13.980
Now in list comprehension it tells you that you can perform all this operation right within a list itself.

26:14.010 --> 26:14.460
Right.

26:14.460 --> 26:16.740
So now see this observe over here.

26:16.770 --> 26:21.840
Now I will go ahead and write for x in range.

26:23.110 --> 26:23.500
ten.

26:23.530 --> 26:23.980
Right.

26:23.980 --> 26:27.400
So here if I go ahead and execute this oh okay.

26:27.400 --> 26:30.820
Right now it is giving me an error because it is invalid syntax I get it okay.

26:30.850 --> 26:32.830
Now let's let's do this okay.

26:32.860 --> 26:35.860
So first I have written for x in range of ten.

26:35.860 --> 26:37.990
So this is basically iterating through this.

26:37.990 --> 26:40.780
Now the next thing is that what kind of operation I am performing.

26:40.780 --> 26:42.190
So I want to perform x square.

26:42.190 --> 26:45.070
So here if I go ahead and write x square.

26:45.100 --> 26:51.040
So list comprehension basically has two important things what we want as an output and what is the kind

26:51.040 --> 26:52.150
of operation that we are doing.

26:52.180 --> 26:52.480
Right.

26:52.480 --> 26:54.850
So see this is doing some kind of operation.

26:54.850 --> 26:56.230
So that needs to be displayed.

26:56.230 --> 26:57.760
And this is basically my iteration.

26:57.760 --> 26:59.170
So both of them are combined.

26:59.170 --> 27:03.460
If I go ahead and execute this you will be able to see that in a single list.

27:03.460 --> 27:05.440
I am able to get the specific answer.

27:05.440 --> 27:06.820
So here what did I do?

27:06.850 --> 27:12.160
I did not have to create other list, item or list elements as such, right?

27:12.160 --> 27:17.740
All I did is that I probably, uh, you know, executed my code within a line of code.

27:17.740 --> 27:20.290
And what I really want is x square.

27:20.320 --> 27:21.410
I have written it in forward.

27:21.440 --> 27:21.770
Right.

27:21.800 --> 27:25.550
Now let's go ahead and see more examples with respect to list comprehension.

27:25.670 --> 27:27.710
So guys we have just seen one example.

27:27.710 --> 27:30.890
And I hope I know that you may be having some kind of confusion.

27:30.890 --> 27:36.980
So it is a better way that if I really want to make you understand about list comprehension, first

27:36.980 --> 27:43.370
of all, let's talk about a specific syntax like what kind of syntax we specifically use.

27:43.400 --> 27:43.940
Okay.

27:44.030 --> 27:46.610
Now the basic syntax okay.

27:46.670 --> 27:49.820
Let me just make this as a markdown okay.

27:50.090 --> 27:51.740
Markdown over here okay.

27:51.770 --> 27:54.350
List comprehension okay.

27:54.500 --> 27:55.700
And this is important.

27:55.700 --> 27:58.820
So that is the reason I'm also going to show you the syntax over here.

27:58.850 --> 27:59.270
Okay.

27:59.300 --> 28:02.390
First of all the basic syntax.

28:02.420 --> 28:02.930
Okay.

28:03.020 --> 28:05.540
Now basic syntax is nothing.

28:05.540 --> 28:11.270
But it looks something like this expression for item in Iterables.

28:11.300 --> 28:11.630
Right.

28:11.630 --> 28:16.370
So that is what we have done for item in iterable which is traversing everything.

28:16.370 --> 28:20.030
And this expression is going to perform on all the single items.

28:20.060 --> 28:22.460
Okay, this is the basic syntax.

28:22.490 --> 28:23.030
Okay.

28:23.060 --> 28:27.380
Now I may also have other option like with conditional logic.

28:27.410 --> 28:27.710
Okay.

28:27.710 --> 28:29.780
If I want to apply some logic over here.

28:29.810 --> 28:33.650
So with conditional logic the expression looks a little bit different.

28:33.680 --> 28:34.070
Okay.

28:34.100 --> 28:37.340
And let me just show you this particular expression also okay.

28:37.370 --> 28:41.180
So here you can see expression for item in a table if condition.

28:41.180 --> 28:42.140
Also I can put.

28:42.170 --> 28:44.630
So I'm putting if condition over here.

28:44.630 --> 28:46.730
So any kind of conditional logic is there.

28:46.730 --> 28:50.270
You have to probably put it at the last iterate.

28:50.300 --> 28:54.620
Whatever iteration you really want to do, you want to put in the center and any kind of expression

28:54.620 --> 28:55.400
that you want to perform.

28:55.400 --> 28:56.870
You can put it in the starting.

28:56.900 --> 28:57.380
Okay.

28:57.410 --> 29:01.460
Now based on this we will try to see some kind of example okay.

29:01.490 --> 29:05.120
So but remember this this is super super important okay.

29:05.120 --> 29:08.240
And you have to use with respect to this itself right.

29:08.270 --> 29:11.150
So let's consider one example.

29:11.840 --> 29:15.260
So let me go ahead and write basic list comprehension.

29:18.120 --> 29:18.660
Okay.

29:18.840 --> 29:22.860
Let's say I want to do a square of all the number.

29:22.890 --> 29:23.520
Okay.

29:23.580 --> 29:25.530
Square of all the number.

29:26.520 --> 29:26.880
Okay.

29:26.910 --> 29:28.410
Square of a set of numbers.

29:28.410 --> 29:35.910
So I will write for x or for num in range of ten.

29:35.940 --> 29:36.450
Right.

29:36.480 --> 29:41.010
And for every of this number I just need to do num square.

29:42.210 --> 29:42.840
Right.

29:43.110 --> 29:43.920
Square.

29:46.230 --> 29:46.860
Done.

29:46.890 --> 29:52.440
Now if I go ahead and print this in short what I'm actually going to get, I'm going to basically get

29:52.440 --> 29:53.460
the square of this number.

29:53.490 --> 29:55.080
Now what condition I have applied over here.

29:55.110 --> 29:57.660
Basic syntax for item in iterable.

29:57.660 --> 29:59.760
And then I have expression okay.

29:59.820 --> 30:01.620
Now coming to the next one okay.

30:01.650 --> 30:06.180
Let's say let's consider with list comprehension with condition okay.

30:06.210 --> 30:08.790
A specific condition over here okay.

30:08.790 --> 30:14.730
And let's say I will try to find out from a list of elements which are which are basically even numbers.

30:14.760 --> 30:15.840
Okay, okay.

30:15.870 --> 30:17.140
Which are even numbers.

30:17.170 --> 30:22.720
Now, let's say if I go ahead and write in for loop for I in range ten.

30:22.900 --> 30:23.530
Okay.

30:24.730 --> 30:30.250
If I go ahead and write, if I colon two is double equal to zero right.

30:30.280 --> 30:32.470
Then what I have to do print.

30:32.710 --> 30:37.120
Or I will probably create a list and I'll append all the even elements right.

30:37.150 --> 30:40.750
So let's say I have created a list an empty list over here.

30:40.780 --> 30:47.650
And now what I'm actually going to do I'm going to basically write list dot append list dot append.

30:48.070 --> 30:51.400
And here I'm going to basically write my I right.

30:51.430 --> 30:58.210
So finally if I go ahead and print my list, you'll be able to see that all the even elements will come

30:58.240 --> 31:00.370
right till this particular ten number.

31:00.400 --> 31:00.910
Right.

31:01.360 --> 31:06.460
But here you need to see how do I convert this into list comprehension.

31:06.460 --> 31:10.030
And I showed you one expression with conditional logic.

31:10.060 --> 31:12.640
Expression is over here for item in iterable is here.

31:12.640 --> 31:13.960
And if condition is over here.

31:13.990 --> 31:17.270
Now the same thing I will try to convert this into a list comprehension.

31:17.270 --> 31:22.250
So I will write for I or for num in range.

31:22.760 --> 31:29.120
Range 20 okay or ten okay, I have to display the number itself so I will write number.

31:29.120 --> 31:31.430
I don't need to even apply any expression.

31:31.430 --> 31:34.130
But here I will go ahead and write one if condition.

31:34.130 --> 31:40.460
I will say hey if num percentile two or modulus two is double equal to zero.

31:40.520 --> 31:45.290
Now this basically becomes my even underscore numbers.

31:45.320 --> 31:48.950
Right now here I do not have to even create a new list.

31:48.980 --> 31:49.490
Right.

31:49.490 --> 31:51.830
All I'm doing it in one single line of code.

31:51.830 --> 31:54.890
So this way my execution will happen quicker right?

31:54.920 --> 31:55.940
It will be faster.

31:56.150 --> 31:59.210
So I hope you are getting this as an idea.

31:59.240 --> 32:01.010
Okay, now one more.

32:01.040 --> 32:02.360
One more thing, is there?

32:02.390 --> 32:02.600
Okay.

32:02.630 --> 32:07.820
One more very important, uh, thing is there, which is again a type of list comprehension you can

32:07.820 --> 32:11.150
basically say which is called as nested list comprehension.

32:11.150 --> 32:13.160
So let me just go ahead and write it down.

32:13.220 --> 32:22.310
So here you have something called as nested list comprehension okay.

32:22.310 --> 32:23.960
And it is good to know all these things.

32:23.960 --> 32:28.340
Guys I am trying my level best so that you will be able to understand multiple things.

32:28.370 --> 32:28.910
Okay.

32:29.270 --> 32:36.020
So here you can see and here you can see now what is so different when compared to this okay.

32:36.080 --> 32:40.610
Now here we are iterating through two different iterables.

32:40.610 --> 32:47.060
So for item in iterable one for item two in iterable two then we are writing an expression.

32:47.060 --> 32:49.190
So that basically means if I have two list.

32:49.190 --> 32:54.290
And then on top of that two list I want to perform any kind of list comprehension.

32:54.290 --> 32:56.570
Then I can use this nested list comprehension.

32:56.570 --> 32:59.060
So let me show you one perfect example.

32:59.090 --> 32:59.630
Okay.

32:59.660 --> 33:05.480
Let me just go ahead and write it over here and let me write it as nested list.

33:07.880 --> 33:10.490
Comprehension okay.

33:11.430 --> 33:12.870
Comprehension.

33:14.520 --> 33:17.220
So let me go ahead and create my list one.

33:17.700 --> 33:19.320
And this will be 123.

33:19.530 --> 33:20.250
Okay.

33:20.640 --> 33:34.050
Or I'll take one more element for let me say this is my list two which will be nothing but a, b, C,

33:35.610 --> 33:36.210
d.

33:36.240 --> 33:38.160
Okay, so these are my four elements.

33:38.310 --> 33:46.710
Now let me do one very simple thing okay I will try to make a pair pairs of list one and list two elements

33:46.740 --> 33:47.250
okay.

33:47.340 --> 33:51.150
So first of all I will iterate through list one.

33:51.150 --> 33:54.540
So let me just go ahead and write for I in list one.

33:54.570 --> 33:55.140
Okay.

33:55.230 --> 33:59.610
Then I will iterate through list two for j in list two okay.

33:59.610 --> 34:01.980
And then I have to pair it.

34:01.980 --> 34:07.200
Right now for pairing I will be using a tuple I have not discussed yet about a tuple, but I'm just

34:07.200 --> 34:09.810
going to take this I and j and pair it together.

34:09.840 --> 34:11.410
Okay, just write it in this way.

34:11.440 --> 34:13.690
Okay, now you can see.

34:13.690 --> 34:17.440
Or if you don't want to, like, write like this, you can also use list over here.

34:17.740 --> 34:18.040
Okay.

34:18.070 --> 34:19.960
Let's see whether this will work or not.

34:19.960 --> 34:22.510
And now I'm just going to print pair.

34:24.340 --> 34:25.030
Okay.

34:25.180 --> 34:25.810
Appear.

34:25.840 --> 34:27.490
Appear have written pair.

34:27.790 --> 34:33.460
Okay so here you can see one comma one comma b one comma c one comma two comma two comma b two comma

34:33.490 --> 34:34.360
c two comma d.

34:34.450 --> 34:40.120
So it is just doing all the pairing 1A1B1C1D2A2B2C2D.

34:40.120 --> 34:41.620
So this is what is happening.

34:41.650 --> 34:44.770
First of all this will iterate right with respect to one element.

34:44.770 --> 34:46.930
Then it will iterate all the elements right.

34:46.960 --> 34:49.810
We can also write this in this particular way also.

34:49.840 --> 34:50.080
Right.

34:50.110 --> 34:53.080
But again a lot of lines of code we really need to write.

34:53.080 --> 34:55.060
But this is really really powerful.

34:55.060 --> 34:59.650
And here you can actually see with the help of nested list comprehension we are able to do it right

34:59.740 --> 35:01.450
now in Python.

35:01.450 --> 35:04.630
Also you have lot of inbuilt functions right.

35:04.630 --> 35:13.190
So we can actually use list comprehension List comprehension with function calls.

35:13.400 --> 35:20.210
You can create your own custom function and all, but right now I'm going to show you some, uh, inbuilt

35:20.210 --> 35:20.720
functions.

35:20.750 --> 35:21.290
Okay.

35:21.290 --> 35:23.240
So inbuilt function will try to see.

35:23.240 --> 35:28.340
So list comprehension with this let's say and I will I'll show you the code over here.

35:28.340 --> 35:32.690
So here I have words like hello world Python list comprehension.

35:32.720 --> 35:34.400
Now see everybody focus.

35:34.400 --> 35:37.310
So I'm writing for words in words and I'm just saying length of word.

35:37.340 --> 35:37.730
Right.

35:37.730 --> 35:40.580
So it is just going to give us the length of word over here.

35:40.610 --> 35:41.030
Right.

35:41.030 --> 35:44.330
And how easily we are able to see this particular output.

35:44.360 --> 35:44.960
Right.

35:44.960 --> 35:46.970
And this looks amazing.

35:46.970 --> 35:47.270
Right.

35:47.270 --> 35:51.890
And most of the things are basically very much simple over here right now.

35:51.890 --> 35:58.970
Uh, there is also one more list comprehension technique where you can use else block also.

35:58.970 --> 36:01.610
So, uh, I will give you that as an assignment.

36:01.610 --> 36:02.900
Please make sure that you do it.

36:02.900 --> 36:07.340
But don't worry as we go ahead and run, learn more about the tuples and all there.

36:07.340 --> 36:12.740
Also, we'll be covering more about it, but I hope you got an idea with respect to list comprehension.

36:12.740 --> 36:19.880
And this was all about the discussion with respect to list, and I think I tried my level best to cover

36:19.880 --> 36:21.740
almost each and every thing.

36:21.830 --> 36:22.220
Okay.

36:22.250 --> 36:26.300
And at the end of the day, you really need to try more and more to understand more.

36:26.330 --> 36:28.310
Example, unless you don't practice.

36:28.310 --> 36:29.660
Uh, I don't think so.

36:29.660 --> 36:33.050
You will be able to do any perfection in this.

36:33.050 --> 36:33.380
Right.

36:33.380 --> 36:35.150
So more examples, more things.

36:35.150 --> 36:39.620
But at the end of the day, I would like to give the conclusion of this lesson and probably talk about

36:39.620 --> 36:42.320
it, you know, because list is something really important.

36:42.320 --> 36:43.340
So the list.

36:44.060 --> 36:48.620
So here you can see I have given some conclusion with respect to the list comprehension are powerful

36:48.620 --> 36:49.130
and concise.

36:49.130 --> 36:55.610
To create list in Python they are syntactically syntactically compact and can replace more verbose looping

36:55.610 --> 36:56.180
construct.

36:56.210 --> 37:00.980
Understand the syntax of list comprehension will help you write cleaner and more efficient Python code,

37:01.010 --> 37:01.550
right?

37:01.610 --> 37:03.470
So yes, this was it.

37:03.470 --> 37:07.220
Uh, I will see you all in the next video where we will be talking about the next data structure.

37:07.250 --> 37:07.430
Thank.
