1 00:00:00,830 --> 00:00:02,410 - [Instructor] In this self-check exercise, 2 00:00:02,410 --> 00:00:05,790 we actually have two different exercises for you to perform. 3 00:00:05,790 --> 00:00:08,780 In the first case, we'd like you to use, in one statement, 4 00:00:08,780 --> 00:00:12,580 both the split and the join methods to reformat the name, 5 00:00:12,580 --> 00:00:17,550 Pamela White as the string, White comma space Pamela. 6 00:00:17,550 --> 00:00:19,990 And in the second, we'd like you to go ahead 7 00:00:19,990 --> 00:00:22,880 and use the partition and rpartition methods 8 00:00:22,880 --> 00:00:27,287 to extract from this URL, the substrings 9 00:00:27,287 --> 00:00:32,210 www.deitel.com and books/PyCDS, 10 00:00:33,540 --> 00:00:36,140 which is a shorthand notation internally 11 00:00:36,140 --> 00:00:39,630 at Deitel for one of our new Python textbooks. 12 00:00:39,630 --> 00:00:42,800 So, go ahead and try these two exercises, 13 00:00:42,800 --> 00:00:45,163 and then come back to see the answers. 14 00:00:51,780 --> 00:00:53,960 Okay, let's go ahead and reveal the answer 15 00:00:53,960 --> 00:00:55,540 to the first exercise here. 16 00:00:55,540 --> 00:00:59,920 So, of course, we have nested sets of parentheses here. 17 00:00:59,920 --> 00:01:03,530 So what we're going to do is actually several fold. 18 00:01:03,530 --> 00:01:06,540 We're going to begin, with the string, Pamela White, 19 00:01:06,540 --> 00:01:10,170 and we're going to split that into a list of strings. 20 00:01:10,170 --> 00:01:13,990 We're passing the resulting list into the reversed method 21 00:01:13,990 --> 00:01:17,450 which you probably remember from an earlier lesson, 22 00:01:17,450 --> 00:01:20,640 which is going to reverse the items within that list. 23 00:01:20,640 --> 00:01:24,460 So now we have a list with its items in reverse order. 24 00:01:24,460 --> 00:01:28,250 And then we're going to join those two items 25 00:01:28,250 --> 00:01:29,830 in the resulting list, 26 00:01:29,830 --> 00:01:33,340 separating them with a comma and a space. 27 00:01:33,340 --> 00:01:36,200 So if I go ahead and execute that you can see that indeed, 28 00:01:36,200 --> 00:01:39,880 we were able to produce the resulting format 29 00:01:39,880 --> 00:01:42,160 that was described up above. 30 00:01:42,160 --> 00:01:43,680 Now, let's go ahead and take a look 31 00:01:43,680 --> 00:01:47,050 at the second exercise here. 32 00:01:47,050 --> 00:01:49,060 We're going to start with the string 33 00:01:49,060 --> 00:01:51,850 that was specified in the problem statement. 34 00:01:51,850 --> 00:01:54,340 And, whoops, yeah I did execute it, 35 00:01:54,340 --> 00:01:57,230 and now let's go ahead and reveal the answers 36 00:01:57,230 --> 00:01:58,750 and talk about them here. 37 00:01:58,750 --> 00:02:03,750 So, the first thing we decided to do was to pick off, 38 00:02:04,010 --> 00:02:06,290 or break apart the URL string 39 00:02:06,290 --> 00:02:09,440 at the colon and the slash slash. 40 00:02:09,440 --> 00:02:11,550 So colon and slash slash here. 41 00:02:11,550 --> 00:02:13,433 And let's go ahead and do that. 42 00:02:14,720 --> 00:02:17,470 So what we're going to get as a result of that is 43 00:02:17,470 --> 00:02:22,470 http:// and then the rest of the URL. 44 00:02:23,490 --> 00:02:28,390 Then we used partition again to pick off the host 45 00:02:28,390 --> 00:02:32,480 which is www.deitel.com from the beginning 46 00:02:32,480 --> 00:02:36,690 of the resulting rest of URL string up above. 47 00:02:36,690 --> 00:02:41,397 So we're partitioning that string at the first forward slash 48 00:02:41,397 --> 00:02:45,120 and again we're working on this highlighted portion 49 00:02:45,120 --> 00:02:46,980 of the original string now. 50 00:02:46,980 --> 00:02:51,589 So we're going to get, as the host, www.deitel.com. 51 00:02:51,589 --> 00:02:55,380 As the separator, we're going to get the forward slash. 52 00:02:55,380 --> 00:02:59,400 And then the rest of the URL will be document with path. 53 00:02:59,400 --> 00:03:01,750 So we'll go ahead and execute that. 54 00:03:01,750 --> 00:03:04,030 And just to prove that we picked off the host, 55 00:03:04,030 --> 00:03:07,440 there is the first of the two strings it wanted me to get. 56 00:03:07,440 --> 00:03:12,440 And then, separately, we wanted to pick off books/PyCDS, 57 00:03:12,980 --> 00:03:15,920 so for that purpose, we used our partition 58 00:03:15,920 --> 00:03:19,890 because, what we now have left from the original string, 59 00:03:19,890 --> 00:03:21,770 is this substring. 60 00:03:21,770 --> 00:03:24,660 So what we're going to do is search backwards 61 00:03:24,660 --> 00:03:27,230 until we find this forward slash. 62 00:03:27,230 --> 00:03:29,300 And then we'll have one of the substrings 63 00:03:29,300 --> 00:03:32,120 will be the piece that we need to pick off here. 64 00:03:32,120 --> 00:03:34,400 So, if I go ahead and execute this, 65 00:03:34,400 --> 00:03:36,870 we can see that by searching backwards, 66 00:03:36,870 --> 00:03:41,400 the path is indeed books/PyCDS. 67 00:03:41,400 --> 00:03:44,100 So it was a little bit involved, but as you can see, 68 00:03:44,100 --> 00:03:46,410 we were able to pick off the two pieces 69 00:03:46,410 --> 00:03:49,853 using the methods specified in the problem statement.