1 00:00:00,000 --> 00:00:04,964 This function returns the mean value of a list 2 00:00:04,965 --> 00:00:07,258 but we want to make it more intelligent. 3 00:00:07,259 --> 00:00:09,636 We want the function to return the mean 4 00:00:09,637 --> 00:00:13,098 even if the input value is a dictionary. 5 00:00:13,099 --> 00:00:15,412 So when the input value is a list, it will 6 00:00:15,413 --> 00:00:19,284 going to apply a specific algorithm and return the specific 7 00:00:19,285 --> 00:00:21,252 value which is the mean of the list. 8 00:00:21,253 --> 00:00:23,828 When it's a dictionary, it's going to check if 9 00:00:23,829 --> 00:00:27,906 it's a dictionary and can apply the corresponding algorithm 10 00:00:27,907 --> 00:00:30,450 that calculates the mean value of a dictionary. 11 00:00:30,451 --> 00:00:31,866 So we know that 12 00:00:31,867 --> 00:00:34,233 [Author typing] 13 00:00:34,234 --> 00:00:36,274 sum monday_temperatures 14 00:00:36,275 --> 00:00:39,136 divided by length of monday_temperatures gives 15 00:00:39,137 --> 00:00:41,980 you the mean of the list. 16 00:00:42,590 --> 00:00:47,478 Similarly, student_grades which is a dictionary, its values, 17 00:00:47,479 --> 00:00:50,490 the sum of its values divided by the length 18 00:00:50,491 --> 00:00:56,388 of student_grades dictionary will give you the mean. 19 00:00:56,389 --> 00:01:00,990 So we want our function to check and make a decision. 20 00:01:02,050 --> 00:01:05,459 This is a parameter, let me change it to value. 21 00:01:05,460 --> 00:01:09,666 [Author typing] 22 00:01:09,670 --> 00:01:13,032 value is a more meaningful name since what 23 00:01:13,033 --> 00:01:15,128 we are processing will not only be a 24 00:01:15,129 --> 00:01:17,350 list, but it can also be a dictionary. 25 00:01:17,930 --> 00:01:20,028 And then under the function 26 00:01:20,029 --> 00:01:22,330 everything has to be indented. 27 00:01:22,331 --> 00:01:26,354 You can see the whole body of the function is indented. 28 00:01:26,355 --> 00:01:28,688 So the conditional block that I'm going to 29 00:01:28,689 --> 00:01:32,350 write here is also going to be indented. 30 00:01:32,351 --> 00:01:34,670 It starts with if. 31 00:01:34,671 --> 00:01:38,304 If you remember we use a type function earlier in 32 00:01:38,305 --> 00:01:44,628 the course which returned the type of an object. 33 00:01:44,629 --> 00:01:46,612 For example, this is a dictionary, an 34 00:01:46,613 --> 00:01:49,194 empty one, but it's still a dictionary. 35 00:01:49,195 --> 00:01:52,390 So what you can do here is you can say 36 00:01:52,391 --> 00:01:58,814 if type value double assignment operator which means equal. 37 00:01:58,815 --> 00:02:02,190 It's a comparison operator, it checks equality. 38 00:02:02,191 --> 00:02:07,196 If that is a dict: enter, and 39 00:02:07,197 --> 00:02:09,586 it has to be indented with four spaces. 40 00:02:09,587 --> 00:02:12,546 So you see, it's another level of indentation. 41 00:02:12,547 --> 00:02:16,120 It's one here for if and this is for the function. 42 00:02:17,470 --> 00:02:22,010 So here the_mean will be equal to sum 43 00:02:23,070 --> 00:02:27,233 of value.values 44 00:02:27,234 --> 00:02:29,466 [Author typing] 45 00:02:29,467 --> 00:02:33,866 divide by the length of value. 46 00:02:33,970 --> 00:02:37,436 So this is a dictionary, dict.values, 47 00:02:37,437 --> 00:02:40,154 and length of the dictionary. 48 00:02:40,155 --> 00:02:47,096 I have to close the sum function call there, like that 49 00:02:47,097 --> 00:02:53,030 and enter if you are done with the if block. 50 00:02:53,031 --> 00:02:57,771 So if that's all what you want to check, then you say else 51 00:02:57,772 --> 00:03:00,133 [No audio] 52 00:03:00,134 --> 00:03:03,628 and we have this code which has 53 00:03:03,629 --> 00:03:08,990 to be indented under else as well and that's it. 54 00:03:08,991 --> 00:03:10,460 Let me try this. 55 00:03:12,190 --> 00:03:14,912 So with student_grades the dictionary as 56 00:03:14,913 --> 00:03:19,180 input, we got this value here. 57 00:03:20,856 --> 00:03:21,989 If I used 58 00:03:21,990 --> 00:03:26,200 [Author typing] 59 00:03:26,201 --> 00:03:27,233 the list 60 00:03:27,234 --> 00:03:30,666 [No audio] 61 00:03:30,667 --> 00:03:34,000 monday_temperatures, it's 62 00:03:34,000 --> 00:03:36,148 going to give me the other value which 63 00:03:36,149 --> 00:03:38,522 is the mean of the monday_temperatures. 64 00:03:38,523 --> 00:03:41,034 So that's an if and else conditional. 65 00:03:41,035 --> 00:03:44,380 But let me explain it line by line in the next video. 66 00:03:44,381 --> 00:03:48,266 [Outro sound]