Throughout my experience with working with large data
sets, I've noticed some techniques that data collecting
institutes use to save storage and make them
their data have less space
on computer disks. A common technique
is not to use decimals.
For example, if you search for temperature
data, you'll not see the actual temperatures.
Let's say these are celsius.
You'll not see them like that, but that
you'll see them without the dots because that
will save storage in the servers.
So one character less, that means some bytes less.
So your duty as a programmer is to actually divide all
those values by 10, so that you get the actual data.
So let's say these data were in some text files, and
we open these data with Python, and the course actually covers
how to manage, how to open text files in Python.
But let us skip that part for now.
So let's say we got them loaded as a list here.
Now we want to actually divide by 10 any of them.
So how do you do that?
Well, a technique is to iterate over temps.
So for temp in temps, and in each iteration,
you want to do temp divided by ten.
But where do we store this temp divided by ten?
Well, we can store it in a new list.
Let's say new_temps.
That is an empty list for now.
So the loop will iterate through this list, and in each iteration,
[Author typing]
we going to append this value to new_temps.
So append this value. That looks okay,
and then print(new temps).
Let me go ahead and execute that.
[Author typing]
So this is the desired output.
Now, that is very correct.
But there is a neater way to do
this in just one line of Python code,
and that is by using list comprehensions.
It goes like this.
You don't have to create an empty list
because a list will be generated dynamically.
You'd say temp / 10 for temp in temps,
print(new_temps) to see what we get,
execute, and you get exactly the same output.
So that is a list comprehension.
It's a way to build lists without having to
create a for loop, a standard for loop, because
we actually have an inline for loop in here.
So what's going on here is that we have an
iteration here, and in each iteration we're going to store
this value in the list, in the new_temps list.
So this is like saying store temp divided by ten,
but Python will say, okay, but what is temp?
It's a new variable.
We haven't defined it anywhere.
And then we say, well, for temp in temps.
So temp is a variable of temps.
So that's how you create a list with these
values for each of the values of temps.
That is a list comprehension.
[Outro sound]