1 00:00:00,000 --> 00:00:02,772 So you are a teacher and you wanted 2 00:00:02,773 --> 00:00:05,492 to calculate the average grade of your students. 3 00:00:05,493 --> 00:00:09,012 And we did that using this algorithm here 4 00:00:09,013 --> 00:00:12,030 and this data structure to store the grades. 5 00:00:13,010 --> 00:00:15,498 The problem here is you don't 6 00:00:15,499 --> 00:00:18,020 know which grade is of who. 7 00:00:18,021 --> 00:00:22,020 So while a list is a good data structure to store 8 00:00:22,021 --> 00:00:26,092 an array of items, it's not good enough when these 9 00:00:26,093 --> 00:00:30,316 items have some sort of identity attached to them. 10 00:00:30,317 --> 00:00:33,733 In that case, you want to use a dictionary. 11 00:00:33,734 --> 00:00:36,266 [Author typing] 12 00:00:36,267 --> 00:00:40,400 Let's say student_grades, curly 13 00:00:40,400 --> 00:00:43,610 brackets, that's the syntax for a dictionary. 14 00:00:44,750 --> 00:00:49,014 And then you use names of your students, let's 15 00:00:49,015 --> 00:00:53,392 say Marry, a colon, make some space or no 16 00:00:53,393 --> 00:00:55,828 space, whatever you prefer, but it's good to have 17 00:00:55,829 --> 00:00:58,554 a space there to make it more readable. 18 00:00:58,555 --> 00:01:01,790 And then you write the grade of Marry, 19 00:01:02,870 --> 00:01:07,903 let's say Sim:8.8 20 00:01:07,904 --> 00:01:10,166 [Author typing] 21 00:01:10,167 --> 00:01:11,166 and John 22 00:01:11,167 --> 00:01:13,100 [Author typing] 23 00:01:13,101 --> 00:01:15,976 :7.5. 24 00:01:15,977 --> 00:01:17,788 So the difference between the dictionary and 25 00:01:17,789 --> 00:01:20,898 the list is the brackets, different brackets. 26 00:01:20,899 --> 00:01:24,748 And then this is considered an item in a 27 00:01:24,749 --> 00:01:28,188 dictionary, this is considered an item in a list. 28 00:01:28,189 --> 00:01:32,688 So items in a dictionary are made of keys, this 29 00:01:32,689 --> 00:01:35,740 is a key and values, this is a value. 30 00:01:36,270 --> 00:01:39,312 A list would be more appropriate if we had 31 00:01:39,313 --> 00:01:43,310 to store, for example, an array of temperature values. 32 00:01:45,170 --> 00:01:49,876 Let's say Monday had 33 00:01:49,877 --> 00:01:54,350 these temperatures, monday_temperatures. 34 00:01:54,351 --> 00:01:56,328 And lastly, how do we calculate the 35 00:01:56,329 --> 00:01:59,230 average when we have a dictionary? 36 00:01:59,231 --> 00:02:03,102 Since these are pairs of keys and values, 37 00:02:03,103 --> 00:02:06,360 you can't just make the sum like that. 38 00:02:07,050 --> 00:02:11,772 You need to specify the sum of what you want to get. 39 00:02:11,773 --> 00:02:17,730 So student_grades and if you check dir(dict) 40 00:02:17,731 --> 00:02:22,118 for dictionary, you'll see that dictionaries have these values, 41 00:02:22,119 --> 00:02:28,528 which is a method, dict.values, it is a 42 00:02:28,529 --> 00:02:33,730 method and it provides a view of dictionary values. 43 00:02:33,731 --> 00:02:35,348 In simple words, it gives you 44 00:02:35,349 --> 00:02:37,466 the values of a dictionary. 45 00:02:37,467 --> 00:02:41,962 So if you get this dictionary Q for quit 46 00:02:41,963 --> 00:02:49,410 here, paste it here and see student_grade values 47 00:02:50,390 --> 00:02:54,504 that will give you this data type. 48 00:02:54,505 --> 00:02:56,248 So it's still a data type. 49 00:02:56,249 --> 00:02:59,356 It does look like a list, it's not exactly a list, 50 00:02:59,357 --> 00:03:04,220 but it behaves like a list with these three values there. 51 00:03:04,221 --> 00:03:06,748 So it's a dict values type. 52 00:03:06,749 --> 00:03:11,522 That method produces this type and therefore 53 00:03:11,523 --> 00:03:15,596 you can add that in there. 54 00:03:15,597 --> 00:03:19,212 Don't forget the parentheses, don't forget to save and 55 00:03:19,213 --> 00:03:21,562 don't forget to execute to get the output. 56 00:03:21,563 --> 00:03:25,226 And this is the average value of the dictionary values. 57 00:03:25,227 --> 00:03:31,492 To get the keys of dictionary, just do keys, and 58 00:03:31,493 --> 00:03:34,948 you get this dict keys type with the keys of 59 00:03:34,949 --> 00:03:39,390 the dictionary as items of that dict keys array. 60 00:03:39,391 --> 00:03:43,233 [Outro sound]