So you are a teacher and you wanted
to calculate the average grade of your students.
And we did that using this algorithm here
and this data structure to store the grades.
The problem here is you don't
know which grade is of who.
So while a list is a good data structure to store
an array of items, it's not good enough when these
items have some sort of identity attached to them.
In that case, you want to use a dictionary.
[Author typing]
Let's say student_grades, curly
brackets, that's the syntax for a dictionary.
And then you use names of your students, let's
say Marry, a colon, make some space or no
space, whatever you prefer, but it's good to have
a space there to make it more readable.
And then you write the grade of Marry,
let's say Sim:8.8
[Author typing]
and John
[Author typing]
:7.5.
So the difference between the dictionary and
the list is the brackets, different brackets.
And then this is considered an item in a
dictionary, this is considered an item in a list.
So items in a dictionary are made of keys, this
is a key and values, this is a value.
A list would be more appropriate if we had
to store, for example, an array of temperature values.
Let's say Monday had
these temperatures, monday_temperatures.
And lastly, how do we calculate the
average when we have a dictionary?
Since these are pairs of keys and values,
you can't just make the sum like that.
You need to specify the sum of what you want to get.
So student_grades and if you check dir(dict)
for dictionary, you'll see that dictionaries have these values,
which is a method, dict.values, it is a
method and it provides a view of dictionary values.
In simple words, it gives you
the values of a dictionary.
So if you get this dictionary Q for quit
here, paste it here and see student_grade values
that will give you this data type.
So it's still a data type.
It does look like a list, it's not exactly a list,
but it behaves like a list with these three values there.
So it's a dict values type.
That method produces this type and therefore
you can add that in there.
Don't forget the parentheses, don't forget to save and
don't forget to execute to get the output.
And this is the average value of the dictionary values.
To get the keys of dictionary, just do keys, and
you get this dict keys type with the keys of
the dictionary as items of that dict keys array.
[Outro sound]