- [Instructor] In this self-check exercise,
we actually have two different exercises for you to perform.
In the first case, we'd like you to use, in one statement,
both the split and the join methods to reformat the name,
Pamela White as the string, White comma space Pamela.
And in the second, we'd like you to go ahead
and use the partition and rpartition methods
to extract from this URL, the substrings
www.deitel.com and books/PyCDS,
which is a shorthand notation internally
at Deitel for one of our new Python textbooks.
So, go ahead and try these two exercises,
and then come back to see the answers.
Okay, let's go ahead and reveal the answer
to the first exercise here.
So, of course, we have nested sets of parentheses here.
So what we're going to do is actually several fold.
We're going to begin, with the string, Pamela White,
and we're going to split that into a list of strings.
We're passing the resulting list into the reversed method
which you probably remember from an earlier lesson,
which is going to reverse the items within that list.
So now we have a list with its items in reverse order.
And then we're going to join those two items
in the resulting list,
separating them with a comma and a space.
So if I go ahead and execute that you can see that indeed,
we were able to produce the resulting format
that was described up above.
Now, let's go ahead and take a look
at the second exercise here.
We're going to start with the string
that was specified in the problem statement.
And, whoops, yeah I did execute it,
and now let's go ahead and reveal the answers
and talk about them here.
So, the first thing we decided to do was to pick off,
or break apart the URL string
at the colon and the slash slash.
So colon and slash slash here.
And let's go ahead and do that.
So what we're going to get as a result of that is
http:// and then the rest of the URL.
Then we used partition again to pick off the host
which is www.deitel.com from the beginning
of the resulting rest of URL string up above.
So we're partitioning that string at the first forward slash
and again we're working on this highlighted portion
of the original string now.
So we're going to get, as the host, www.deitel.com.
As the separator, we're going to get the forward slash.
And then the rest of the URL will be document with path.
So we'll go ahead and execute that.
And just to prove that we picked off the host,
there is the first of the two strings it wanted me to get.
And then, separately, we wanted to pick off books/PyCDS,
so for that purpose, we used our partition
because, what we now have left from the original string,
is this substring.
So what we're going to do is search backwards
until we find this forward slash.
And then we'll have one of the substrings
will be the piece that we need to pick off here.
So, if I go ahead and execute this,
we can see that by searching backwards,
the path is indeed books/PyCDS.
So it was a little bit involved, but as you can see,
we were able to pick off the two pieces
using the methods specified in the problem statement.