1 00:00:00,380 --> 00:00:05,700 All right, so we've done a raise, we've done sets, there's one other collection there, a few other 2 00:00:05,700 --> 00:00:10,680 collections actually, but one other collection that's quite important that we use fairly often. 3 00:00:10,680 --> 00:00:12,080 And this is called a dictionary. 4 00:00:12,480 --> 00:00:18,020 Now, if you think of a regular dictionary, it's ordered by letter, right? 5 00:00:18,030 --> 00:00:20,550 So it's got an alphabetical order to it. 6 00:00:21,120 --> 00:00:27,930 But one of the features that it has is that if you go to the section marked A you have all the words 7 00:00:27,930 --> 00:00:34,020 with A and that's exactly exactly the definition of a dictionary in programming as well. 8 00:00:34,260 --> 00:00:41,790 So if I just drop one here, we can define it by saying var dictionary has a type of character Kolon 9 00:00:41,940 --> 00:00:42,630 string. 10 00:00:43,260 --> 00:00:43,620 Right. 11 00:00:43,920 --> 00:00:50,760 So what I'm doing here is giving it a key, which is the letter A and then a value, which is the word 12 00:00:50,760 --> 00:00:51,260 apple. 13 00:00:51,810 --> 00:01:00,210 I could also if I wanted to give it an array of strings and that would actually cover an entire dictionary. 14 00:01:00,420 --> 00:01:01,890 So what have I got in my notes here? 15 00:01:02,320 --> 00:01:09,770 Oh yes, I have a better dictionary so I can paste this in better dictionary. 16 00:01:10,050 --> 00:01:18,110 And in this case, I've got a character which is just one letter and I have an array of strings. 17 00:01:18,120 --> 00:01:18,360 Right. 18 00:01:18,400 --> 00:01:19,830 So that's how you declare an array. 19 00:01:20,790 --> 00:01:23,850 And then I'm saying in this dictionary, I want you to put under way. 20 00:01:24,630 --> 00:01:32,160 And that's represented by this code on Apple and Aardvark writes, We're well on our way to building 21 00:01:32,160 --> 00:01:32,910 a dictionary. 22 00:01:32,910 --> 00:01:37,560 It reminds you of an episode of Blackadder that I've really enjoyed where Baldrick had to write the 23 00:01:37,560 --> 00:01:44,220 dictionary and they went to the letter B and he went big blue wobbly thing what mermaids live in. 24 00:01:45,870 --> 00:01:47,070 I got to watch that actually. 25 00:01:47,640 --> 00:01:47,970 Right. 26 00:01:47,990 --> 00:01:51,570 So how do we add stuff to our dictionary? 27 00:01:51,720 --> 00:01:54,050 Well, better DECT sounds a bit rude. 28 00:01:54,060 --> 00:02:02,350 I know we want to access the element a right to the section on the A and what do we want to do. 29 00:02:02,760 --> 00:02:05,820 Well we want to append something to it now. 30 00:02:06,800 --> 00:02:09,620 We discussed options, which is the question mark symbol. 31 00:02:10,620 --> 00:02:16,930 A dictionary might not have a inside it, so we have to put a question mark here. 32 00:02:17,580 --> 00:02:25,950 So if our system doesn't find a it doesn't continue past this point, you can use if statements to check 33 00:02:25,950 --> 00:02:29,160 if everything's OK, then we're going to put DOT. 34 00:02:29,160 --> 00:02:31,680 And first thing that comes up is append. 35 00:02:32,820 --> 00:02:33,540 That is correct. 36 00:02:33,550 --> 00:02:37,010 We're going to add something to this section. 37 00:02:37,440 --> 00:02:38,700 What are we going to append? 38 00:02:39,770 --> 00:02:41,720 Well, I forgot, so let's add amnesia. 39 00:02:43,470 --> 00:02:49,560 Now we have our better dictionary with Apple, Aardvark and Amnesia, and I'll prove it to you. 40 00:02:51,670 --> 00:02:52,630 By doing the following. 41 00:02:54,790 --> 00:02:58,690 There we have it, Apple, Aardvark and amnesia. 42 00:03:00,070 --> 00:03:06,340 So that's a dictionary we could do the same with B, C, D, E, F, or we could do the same with music 43 00:03:06,340 --> 00:03:15,310 types or whatever you can imagine is required with a dictionary type of array or collection is a better 44 00:03:16,030 --> 00:03:17,110 word to use for that. 45 00:03:17,770 --> 00:03:18,250 Right. 46 00:03:18,880 --> 00:03:21,100 If I wanted to add B to it, we will do that. 47 00:03:22,000 --> 00:03:29,080 We can just go ahead and create that so it doesn't need to exist immediately, right? 48 00:03:30,720 --> 00:03:36,330 But when this case, we're not going to append anything, we're actually going to create it. 49 00:03:40,470 --> 00:03:41,010 B. 50 00:03:42,280 --> 00:03:43,420 In your Bonnett. 51 00:03:44,890 --> 00:03:47,470 And so now if I print that Benedict. 52 00:03:51,560 --> 00:04:00,350 We should get Bee has been Bonnett and a has Apple, Aardvark and amnesia, and of course you can go 53 00:04:00,350 --> 00:04:02,290 on and on like this now. 54 00:04:02,360 --> 00:04:07,360 You wouldn't ever use a dictionary in such a primitive way by just shoving strings into it. 55 00:04:07,760 --> 00:04:12,280 You'd actually have some sort of structure around this in a commercial application. 56 00:04:12,800 --> 00:04:16,140 But this shows you the concept quite well, right? 57 00:04:16,150 --> 00:04:17,120 A bit of homework. 58 00:04:17,900 --> 00:04:25,010 Oh, or because it's less than 10 and you've had two breaks from homework already make a dictionary 59 00:04:25,040 --> 00:04:28,730 that holds names of students by age. 60 00:04:29,660 --> 00:04:33,600 Right, so that's not that straightforward, again, if it sounds difficult. 61 00:04:33,830 --> 00:04:35,850 Stop right on a piece of paper. 62 00:04:35,870 --> 00:04:39,450 What do you think you should do and then translate that to code? 63 00:04:39,890 --> 00:04:40,370 Good luck.