- [Instructor] In this self check exercise,
I'd like you to work with the DEL statement
that we introduced in the preceding video.
So, start out by first creating a list call numbers
with the values one through 15.
And then perform the following two tasks.
Go ahead and delete a slice
that just contains the first four elements,
and show that those elements were removed.
Then delete a slice that starts with
the first element,
and removes every
other element from that point forward
in the rest of the list,
and show us the resulting list once again.
So, go ahead and pause the video
to give those a shot,
then come back to see the answers.
Okay, lets reveal the answers
by first creating the list with
the numbers from one through 15.
So again we're using the range function
to make that super quick and easy for us.
And of course,
we want to see that those values are in the list.
So, the first thing we wanna do now that we have our list,
is delete those first four elements,
the numbers from one through four.
So, let's do that with the DEL statement.
So, here's a slice
that says,
Give me a subset of numbers,
stating from index zero up to,
but not including index four.
So that gives me,
zero, one, two, and three positions.
The fist four elements of that list.
So, if we delete that
and then show you the result afterwards,
you can see that one through four,
have now been removed from the list.
Now, for the second part of the exercise,
we want to delete
every other element.
Starting with the first one.
So, here is an expression
that will do that.
Again, we'll infer
index zero as the start here.
We will infer
the entire length of the remaining
list as the second index in this slice.
And then we're saying,
go every other element through that slice.
So, at this point
we expect to remove five, seven, nine, etc.
And the resulting list,
now contains just the remaining even integers.