Instructor: In this exercise,
we're going to practice some list comprehension.
You're going to write
some list comprehension code of your own,
and you're going to create a new list
from the list of numbers,
where each of the numbers are squared.
So where it's originally 2,
then in the new list, it should become 4,
where it's originally 8, it should become 64,
and so on, and so forth.
If you take a look in the description box,
you can see what the output should look like.
But of course, we want you to actually write the code
that can generate this using list comprehension.
It only takes one line of code to do this.
And you should not need a for loop,
you should not need to write any conditionals.
It should be done using what you've learned
about list comprehension.
And if at any point you get stuck,
take a look in the hints in the description box,
take a look back at the lesson
where you learnt about list comprehension,
and try some things out, print it out, see if it works.
Give it a go now.
I know the solution looks simple.
It is just one line of code, but sometimes one line of code,
the more succinct it is, the harder it is to get there.
So let's go through this together.
We have our squared numbers,
which is a list of the numbers from line 1
where each value is multiplied by itself.
Now, we square a number by multiplying num by num.
Now, what exactly is num?
Well, num is going to be each number inside our list,
which is called numbers.
The full syntax is num multiplied by num
for num in numbers.
If none of this makes sense,
I strongly urge you to take a look back at the lesson
on list comprehension because this is confusing stuff,
and if you've simply printed out the numbers
where you've manually squared each of them
or you used a full blown for loop
where you have an if statement,
then that is not the goal today.
The goal is to practice list comprehension.
So revise it and go back to your code
and modify if necessary.
If you get everything right, then congratulations,
and you're ready to move on to the next lesson.