This function returns the mean value of a list
but we want to make it more intelligent.
We want the function to return the mean
even if the input value is a dictionary.
So when the input value is a list, it will
going to apply a specific algorithm and return the specific
value which is the mean of the list.
When it's a dictionary, it's going to check if
it's a dictionary and can apply the corresponding algorithm
that calculates the mean value of a dictionary.
So we know that
[Author typing]
sum monday_temperatures
divided by length of monday_temperatures gives
you the mean of the list.
Similarly, student_grades which is a dictionary, its values,
the sum of its values divided by the length
of student_grades dictionary will give you the mean.
So we want our function to check and make a decision.
This is a parameter, let me change it to value.
[Author typing]
value is a more meaningful name since what
we are processing will not only be a
list, but it can also be a dictionary.
And then under the function
everything has to be indented.
You can see the whole body of the function is indented.
So the conditional block that I'm going to
write here is also going to be indented.
It starts with if.
If you remember we use a type function earlier in
the course which returned the type of an object.
For example, this is a dictionary, an
empty one, but it's still a dictionary.
So what you can do here is you can say
if type value double assignment operator which means equal.
It's a comparison operator, it checks equality.
If that is a dict: enter, and
it has to be indented with four spaces.
So you see, it's another level of indentation.
It's one here for if and this is for the function.
So here the_mean will be equal to sum
of value.values
[Author typing]
divide by the length of value.
So this is a dictionary, dict.values,
and length of the dictionary.
I have to close the sum function call there, like that
and enter if you are done with the if block.
So if that's all what you want to check, then you say else
[No audio]
and we have this code which has
to be indented under else as well and that's it.
Let me try this.
So with student_grades the dictionary as
input, we got this value here.
If I used
[Author typing]
the list
[No audio]
monday_temperatures, it's
going to give me the other value which
is the mean of the monday_temperatures.
So that's an if and else conditional.
But let me explain it line by line in the next video.
[Outro sound]