1 00:00:00,830 --> 00:00:02,810 - [Instructor] For this Self Check exercise, 2 00:00:02,810 --> 00:00:05,420 we'd like you to work with a couple of the functions 3 00:00:05,420 --> 00:00:08,410 that we just presented in the preceding video. 4 00:00:08,410 --> 00:00:10,820 First, we'd like you to play around 5 00:00:10,820 --> 00:00:14,230 with the min function, both with and without 6 00:00:14,230 --> 00:00:17,300 the second argument, the key argument. 7 00:00:17,300 --> 00:00:19,690 So we'd like you to create a list called foods, 8 00:00:19,690 --> 00:00:21,790 containing the strings that you see here. 9 00:00:21,790 --> 00:00:23,482 And I've already put that statement 10 00:00:23,482 --> 00:00:26,800 in the notebook here for you to look at. 11 00:00:26,800 --> 00:00:28,600 Then what we want you to do is call the 12 00:00:28,600 --> 00:00:32,340 min function with this list as is. 13 00:00:32,340 --> 00:00:34,650 And in a second statement, we want you 14 00:00:34,650 --> 00:00:38,100 to call the min function with the 15 00:00:38,100 --> 00:00:40,590 strings, such that you can ignore 16 00:00:40,590 --> 00:00:42,740 the case for finding the minimum. 17 00:00:42,740 --> 00:00:45,020 So we did that in the preceding video 18 00:00:45,020 --> 00:00:48,590 by calling the lower function, or method, rather, 19 00:00:48,590 --> 00:00:50,500 on each of the strings in the list 20 00:00:50,500 --> 00:00:53,300 as part of calling the min function. 21 00:00:53,300 --> 00:00:54,950 So that's one exercise. 22 00:00:54,950 --> 00:00:56,910 And then separately, we would like you 23 00:00:56,910 --> 00:00:59,930 to use the zip function, that we just introduced, 24 00:00:59,930 --> 00:01:04,360 to zip together two integer lists and create a new list 25 00:01:04,360 --> 00:01:07,230 containing the sum of the elements 26 00:01:07,230 --> 00:01:10,200 from the corresponding indices in both lists. 27 00:01:10,200 --> 00:01:13,150 So elements at position zero in each list 28 00:01:13,150 --> 00:01:16,160 will be added together, elements at position one 29 00:01:16,160 --> 00:01:19,370 in each list will be added together, et cetera, et cetera. 30 00:01:19,370 --> 00:01:22,290 And you can do that a number of different ways. 31 00:01:22,290 --> 00:01:24,230 In the solution, I'll show you, 32 00:01:24,230 --> 00:01:25,860 we'll use a list comprehension. 33 00:01:25,860 --> 00:01:27,550 But go ahead and give that a shot 34 00:01:27,550 --> 00:01:30,033 and then come back to see the results. 35 00:01:34,900 --> 00:01:38,500 OK, let's take a look at the first exercise up above here. 36 00:01:38,500 --> 00:01:40,570 And again, we're going to create the list 37 00:01:40,570 --> 00:01:42,560 first, so I'll go ahead and do that. 38 00:01:42,560 --> 00:01:45,300 Now the first thing we wanted you to do 39 00:01:45,300 --> 00:01:49,260 was try the min function with the list as is. 40 00:01:49,260 --> 00:01:52,470 So don't worry about the uppercase-lowercase sensitivity. 41 00:01:52,470 --> 00:01:55,670 And based on uppercase, lowercase, again, 42 00:01:55,670 --> 00:01:59,050 the uppercase letters are going to have the smallest values, 43 00:01:59,050 --> 00:02:01,930 so Bacon should be the minimum in this case. 44 00:02:01,930 --> 00:02:03,470 And indeed, it is. 45 00:02:03,470 --> 00:02:06,930 However, if you want to do a case-insensitive comparison, 46 00:02:06,930 --> 00:02:11,930 you have that capability by providing that keyword argument. 47 00:02:12,140 --> 00:02:13,860 So in this case, once again, we're saying 48 00:02:13,860 --> 00:02:16,460 for each string, give me the lowercase string 49 00:02:16,460 --> 00:02:18,600 and use those lowercase strings 50 00:02:18,600 --> 00:02:21,550 to figure out the minimum value in foods. 51 00:02:21,550 --> 00:02:23,970 And, as you can see, apples is 52 00:02:23,970 --> 00:02:26,160 the minimum value in that case. 53 00:02:26,160 --> 00:02:28,690 And of course, we did get different results. 54 00:02:28,690 --> 00:02:30,960 And the reason for that, once again, 55 00:02:30,960 --> 00:02:34,690 is that in the first case, we're doing a pure 56 00:02:34,690 --> 00:02:37,825 lexicographical comparison and we're not 57 00:02:37,825 --> 00:02:41,480 specifying how to modify those elements 58 00:02:41,480 --> 00:02:43,210 for the purpose of comparison. 59 00:02:43,210 --> 00:02:45,930 In the second case, we are saying only 60 00:02:45,930 --> 00:02:48,750 look at these strings as all lowercase letters, 61 00:02:48,750 --> 00:02:52,460 and therefore, we got the case-insensitive 62 00:02:52,460 --> 00:02:54,670 comparison in that example. 63 00:02:54,670 --> 00:02:58,390 And apples came out smallest in that case. 64 00:02:58,390 --> 00:03:02,760 Now as far as zipping goes, here is a zip solution 65 00:03:02,760 --> 00:03:05,020 for a couple of sequences of integers. 66 00:03:05,020 --> 00:03:07,760 In this case, two lists of integers, 67 00:03:07,760 --> 00:03:10,040 one containing 10, 20, and 30, 68 00:03:10,040 --> 00:03:12,710 and one containing one, two, and three. 69 00:03:12,710 --> 00:03:14,520 And of course, we can define those 70 00:03:14,520 --> 00:03:16,060 and assign them to variables. 71 00:03:16,060 --> 00:03:18,270 And they don't have to be lists. 72 00:03:18,270 --> 00:03:22,230 They could be other sequences, such as tuples, et cetera. 73 00:03:22,230 --> 00:03:24,210 So what we're going to do is zip together 74 00:03:24,210 --> 00:03:26,070 the pairs of elements from those, 75 00:03:26,070 --> 00:03:28,410 so 10 and one will be zipped together, 76 00:03:28,410 --> 00:03:30,430 20 and two will be zipped together, 77 00:03:30,430 --> 00:03:33,190 and 30 and three will be zipped together. 78 00:03:33,190 --> 00:03:36,250 For each tuple, as we iterate through them, 79 00:03:36,250 --> 00:03:38,920 we will unpack the tuple into the variables 80 00:03:38,920 --> 00:03:42,190 a and b, and then, in the resulting list, 81 00:03:42,190 --> 00:03:47,090 we will add a and b together to produce the list element. 82 00:03:47,090 --> 00:03:49,000 So if I go ahead and execute that, 83 00:03:49,000 --> 00:03:52,250 we can see we get 11, which is 10 plus one, 84 00:03:52,250 --> 00:03:54,730 22, for 20 plus two, 85 00:03:54,730 --> 00:03:57,653 and 33 for 30 plus 3.