Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:01,140 --> 00:00:07,320
This function returns the mean value of a list, but we want to make it more intelligence.
1
2
00:00:07,350 --> 00:00:13,210
We want the function to return to the mean even if the input value is a dictionary.
2
3
00:00:13,230 --> 00:00:19,290
So when the input value is a list it will going to apply a specific algorithm and return the specific
3
4
00:00:19,290 --> 00:00:22,340
value which is the mean of a list. When it's a dictionary
4
5
00:00:22,350 --> 00:00:29,340
it's going to check if it's a dictionary and apply the corresponding algorithm that calculates the mean
5
6
00:00:29,340 --> 00:00:30,450
value of a dictionary.
6
7
00:00:30,510 --> 00:00:31,590
So we know that
7
8
00:00:34,320 --> 00:00:41,750
sum(monday_temperatures) divided by length of monday_temperatures gives you the mean of the list.
8
9
00:00:42,720 --> 00:00:50,310
Similarly student grades which is a dictionary, it's values, the sum of its values divided by the length
9
10
00:00:50,490 --> 00:00:56,370
of student grades dictionary will give you that mean.
10
11
00:00:56,370 --> 00:01:02,190
So we want our function to check and make a decision.
11
12
00:01:02,230 --> 00:01:03,590
This is a parameter.
12
13
00:01:03,640 --> 00:01:09,850
Let me change it to value.
13
14
00:01:09,850 --> 00:01:16,090
Value is a more meaningful name since what we are processing we will not only be a list but it can
14
15
00:01:16,090 --> 00:01:17,800
also be a dictionary.
15
16
00:01:18,250 --> 00:01:22,420
And then under the function everything has to be indented.
16
17
00:01:22,570 --> 00:01:26,590
You can see the whole body of the function is indented.
17
18
00:01:26,590 --> 00:01:32,530
So the conditional block that I'm going to write here is also going to be indented.
18
19
00:01:32,530 --> 00:01:43,570
It starts with if. If you remember we used a type function earlier in the course which returned the type
19
20
00:01:43,660 --> 00:01:44,690
of an object.
20
21
00:01:44,740 --> 00:01:49,270
For example this is a dictionary, an empty one, but it's still a dictionary.
21
22
00:01:49,270 --> 00:01:54,190
So what you can do here is you can say if type value.
22
23
00:01:54,520 --> 00:01:58,870
Double assignment operator which means equal.
23
24
00:01:58,970 --> 00:02:00,240
It's a comparison operator.
24
25
00:02:00,250 --> 00:02:09,670
It checks equality. If that is a dict, a column, enter and it has to be indented with four spaces.
25
26
00:02:09,670 --> 00:02:18,220
So you see it's another level of indentation it's one here for if, and this is for the function, so here
26
27
00:02:18,570 --> 00:02:25,230
the mean will be equal to sum of value
27
28
00:02:25,780 --> 00:02:27,070
dot values
28
29
00:02:29,450 --> 00:02:33,100
divided by the length of value.
29
30
00:02:34,210 --> 00:02:40,250
So this is a dictionary dict.values and length of the dictionary.
30
31
00:02:40,330 --> 00:02:49,160
I have to close the sum function call there like that and enter.
31
32
00:02:49,390 --> 00:02:51,330
If you are done with
32
33
00:02:51,400 --> 00:02:53,090
the if block,
33
34
00:02:53,290 --> 00:02:57,610
so if that's all what you want to check then you say else
34
35
00:03:00,270 --> 00:03:07,230
and we have this code which has to be indented under else as well and that's it.
35
36
00:03:09,180 --> 00:03:15,870
Let me try this. So with student grades, the dictionary as input
36
37
00:03:15,870 --> 00:03:20,150
we got these value here.
37
38
00:03:20,970 --> 00:03:21,840
If I used
38
39
00:03:26,280 --> 00:03:27,030
the list
39
40
00:03:30,810 --> 00:03:38,160
monday_temperatures it's going to give me the other value which is the meaning of the Monday temperatures.
40
41
00:03:38,640 --> 00:03:41,110
So that's an if and else conditional.
41
42
00:03:41,160 --> 00:03:45,360
But let me explain it line by line in the next video.
4122
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.