1
00:00:00,330 --> 00:00:01,290
Instructor: In this exercise,

2
00:00:01,290 --> 00:00:04,890
we're going to practice some list comprehension.

3
00:00:04,890 --> 00:00:05,723
You're going to write

4
00:00:05,723 --> 00:00:08,580
some list comprehension code of your own,

5
00:00:08,580 --> 00:00:10,710
and you're going to create a new list

6
00:00:10,710 --> 00:00:12,300
from the list of numbers,

7
00:00:12,300 --> 00:00:15,510
where each of the numbers are squared.

8
00:00:15,510 --> 00:00:17,280
So where it's originally 2,

9
00:00:17,280 --> 00:00:20,580
then in the new list, it should become 4,

10
00:00:20,580 --> 00:00:23,010
where it's originally 8, it should become 64,

11
00:00:23,010 --> 00:00:24,450
and so on, and so forth.

12
00:00:24,450 --> 00:00:26,820
If you take a look in the description box,

13
00:00:26,820 --> 00:00:29,760
you can see what the output should look like.

14
00:00:29,760 --> 00:00:32,640
But of course, we want you to actually write the code

15
00:00:32,640 --> 00:00:36,480
that can generate this using list comprehension.

16
00:00:36,480 --> 00:00:39,900
It only takes one line of code to do this.

17
00:00:39,900 --> 00:00:41,760
And you should not need a for loop,

18
00:00:41,760 --> 00:00:45,480
you should not need to write any conditionals.

19
00:00:45,480 --> 00:00:47,310
It should be done using what you've learned

20
00:00:47,310 --> 00:00:49,110
about list comprehension.

21
00:00:49,110 --> 00:00:51,180
And if at any point you get stuck,

22
00:00:51,180 --> 00:00:54,330
take a look in the hints in the description box,

23
00:00:54,330 --> 00:00:56,130
take a look back at the lesson

24
00:00:56,130 --> 00:00:59,370
where you learnt about list comprehension,

25
00:00:59,370 --> 00:01:03,360
and try some things out, print it out, see if it works.

26
00:01:03,360 --> 00:01:04,209
Give it a go now.

27
00:01:07,110 --> 00:01:08,700
I know the solution looks simple.

28
00:01:08,700 --> 00:01:12,330
It is just one line of code, but sometimes one line of code,

29
00:01:12,330 --> 00:01:15,480
the more succinct it is, the harder it is to get there.

30
00:01:15,480 --> 00:01:17,670
So let's go through this together.

31
00:01:17,670 --> 00:01:19,770
We have our squared numbers,

32
00:01:19,770 --> 00:01:23,340
which is a list of the numbers from line 1

33
00:01:23,340 --> 00:01:26,760
where each value is multiplied by itself.

34
00:01:26,760 --> 00:01:30,900
Now, we square a number by multiplying num by num.

35
00:01:30,900 --> 00:01:32,340
Now, what exactly is num?

36
00:01:32,340 --> 00:01:37,170
Well, num is going to be each number inside our list,

37
00:01:37,170 --> 00:01:38,670
which is called numbers.

38
00:01:38,670 --> 00:01:41,730
The full syntax is num multiplied by num

39
00:01:41,730 --> 00:01:44,310
for num in numbers.

40
00:01:44,310 --> 00:01:45,900
If none of this makes sense,

41
00:01:45,900 --> 00:01:48,870
I strongly urge you to take a look back at the lesson

42
00:01:48,870 --> 00:01:52,980
on list comprehension because this is confusing stuff,

43
00:01:52,980 --> 00:01:56,760
and if you've simply printed out the numbers

44
00:01:56,760 --> 00:01:58,950
where you've manually squared each of them

45
00:01:58,950 --> 00:02:01,440
or you used a full blown for loop

46
00:02:01,440 --> 00:02:03,300
where you have an if statement,

47
00:02:03,300 --> 00:02:05,250
then that is not the goal today.

48
00:02:05,250 --> 00:02:07,440
The goal is to practice list comprehension.

49
00:02:07,440 --> 00:02:10,229
So revise it and go back to your code

50
00:02:10,229 --> 00:02:11,430
and modify if necessary.

51
00:02:11,430 --> 00:02:13,920
If you get everything right, then congratulations,

52
00:02:13,920 --> 00:02:16,323
and you're ready to move on to the next lesson.

