WEBVTT

00:01.160 --> 00:10.010
Hello, in this session, we will discuss about list of the list comprehensions are used for creating

00:10.010 --> 00:13.010
new lists from other attributes.

00:14.210 --> 00:18.560
These tables could be list dictionaries.

00:20.860 --> 00:29.650
As list comprehension returns, a list that consists of brackets containing the expression which is

00:29.650 --> 00:36.610
executed for each element, along with the follow through, I read over each element.

00:37.240 --> 00:45.920
So we would be using a simple way of doing the same thing which you were doing using a long before.

00:45.920 --> 00:49.470
You let us see an example.

00:50.620 --> 01:05.080
Let us say we want to find out squares of numbers so we can see for I in range twenty and out of these

01:05.080 --> 01:07.870
numbers we want to find out.

01:10.040 --> 01:17.420
The values such that these are squares of these numbers, so we want to find out.

01:18.550 --> 01:20.480
X, is it for you?

01:21.370 --> 01:21.820
I.

01:25.390 --> 01:33.180
Now, I have these values and I want to add these values to a particular list, so let us create a simple

01:33.190 --> 01:33.660
list.

01:33.940 --> 01:40.120
See, a list is equal to square brackets so that it is an empty list.

01:40.660 --> 01:47.410
Now, I want to obtain this value so I can see enlistee dot up in.

01:49.970 --> 01:55.280
X. So this will offend these values to list and then I can.

01:56.750 --> 02:04.200
Simply print the list for you, so let us run this particular piece of code.

02:04.640 --> 02:13.580
So here you can see that I have iteratively created a list of numbers which has squares of numbers from

02:13.580 --> 02:15.230
zero to 90.

02:16.040 --> 02:20.610
Now, I can do this in a much more simpler manner.

02:20.900 --> 02:29.660
So what I can do is I can simply create another list list, too, and I will define it by the two square

02:29.660 --> 02:30.320
brackets.

02:30.560 --> 02:33.830
And inside that I will give for.

02:35.080 --> 02:47.770
I say it's in range, the same thing, just the way we give it here for I in range 20, this is the

02:47.770 --> 02:49.960
exact same language I am giving you.

02:54.060 --> 02:59.850
And instead of doing all these things, I just need to like.

03:02.070 --> 03:03.150
I spoke with.

03:04.450 --> 03:15.790
Here, this means that for every value in these 20, we need to get values which I today's to the power

03:15.800 --> 03:19.420
to, and then we will something else do for you.

03:21.180 --> 03:25.050
So you can see all the same values are being generated.

03:26.100 --> 03:30.940
It is just the same, but only thing is it is a lot more faster.

03:31.710 --> 03:34.510
It is a lot more faster and simpler.

03:35.930 --> 03:43.350
So we can create a much more complex list also using this, so let's create one.

03:43.970 --> 03:44.910
So let us see.

03:44.930 --> 03:53.600
We want to create the same thing, but this time we want to do it for, just say, even numbers or numbers.

03:53.630 --> 03:56.300
So what we can do is we can do it if.

03:57.430 --> 03:57.880
I.

04:04.440 --> 04:10.100
Is equal to zero, so if I is divisible by two.

04:12.650 --> 04:19.520
So in that case, let us get this so it is returning the squares for only.

04:21.930 --> 04:23.040
Even numbers.

04:25.310 --> 04:32.030
Similarly, we can perform any complex operations, I want to multiply three, do it, and then I won't

04:32.030 --> 04:41.240
do that, they add some numbers to it so I can do any complex operation on top of it and I'll be able

04:41.240 --> 04:42.410
to get the results of what?

04:44.430 --> 04:53.310
So this is the usage of list comprehension and you can try different complex list comprehensions so

04:53.790 --> 04:56.500
you can try out different ranges also.

04:56.520 --> 05:00.980
So let's say we want to generate a particular list there.

05:00.990 --> 05:04.740
I want to get something like a particular number.

05:04.740 --> 05:12.720
Say three things for I in range.

05:15.320 --> 05:22.840
For a few more minutes, let's say, we want to open for.

05:25.050 --> 05:27.480
It went the list.

05:33.340 --> 05:34.960
Sorry, this has to be.

05:45.560 --> 05:53.300
So we can go in any direction that we have different kind of results and use them for.
