All right, so we've done a raise, we've done sets, there's one other collection there, a few other
collections actually, but one other collection that's quite important that we use fairly often.
And this is called a dictionary.
Now, if you think of a regular dictionary, it's ordered by letter, right?
So it's got an alphabetical order to it.
But one of the features that it has is that if you go to the section marked A you have all the words
with A and that's exactly exactly the definition of a dictionary in programming as well.
So if I just drop one here, we can define it by saying var dictionary has a type of character Kolon
string.
Right.
So what I'm doing here is giving it a key, which is the letter A and then a value, which is the word
apple.
I could also if I wanted to give it an array of strings and that would actually cover an entire dictionary.
So what have I got in my notes here?
Oh yes, I have a better dictionary so I can paste this in better dictionary.
And in this case, I've got a character which is just one letter and I have an array of strings.
Right.
So that's how you declare an array.
And then I'm saying in this dictionary, I want you to put under way.
And that's represented by this code on Apple and Aardvark writes, We're well on our way to building
a dictionary.
It reminds you of an episode of Blackadder that I've really enjoyed where Baldrick had to write the
dictionary and they went to the letter B and he went big blue wobbly thing what mermaids live in.
I got to watch that actually.
Right.
So how do we add stuff to our dictionary?
Well, better DECT sounds a bit rude.
I know we want to access the element a right to the section on the A and what do we want to do.
Well we want to append something to it now.
We discussed options, which is the question mark symbol.
A dictionary might not have a inside it, so we have to put a question mark here.
So if our system doesn't find a it doesn't continue past this point, you can use if statements to check
if everything's OK, then we're going to put DOT.
And first thing that comes up is append.
That is correct.
We're going to add something to this section.
What are we going to append?
Well, I forgot, so let's add amnesia.
Now we have our better dictionary with Apple, Aardvark and Amnesia, and I'll prove it to you.
By doing the following.
There we have it, Apple, Aardvark and amnesia.
So that's a dictionary we could do the same with B, C, D, E, F, or we could do the same with music
types or whatever you can imagine is required with a dictionary type of array or collection is a better
word to use for that.
Right.
If I wanted to add B to it, we will do that.
We can just go ahead and create that so it doesn't need to exist immediately, right?
But when this case, we're not going to append anything, we're actually going to create it.
B.
In your Bonnett.
And so now if I print that Benedict.
We should get Bee has been Bonnett and a has Apple, Aardvark and amnesia, and of course you can go
on and on like this now.
You wouldn't ever use a dictionary in such a primitive way by just shoving strings into it.
You'd actually have some sort of structure around this in a commercial application.
But this shows you the concept quite well, right?
A bit of homework.
Oh, or because it's less than 10 and you've had two breaks from homework already make a dictionary
that holds names of students by age.
Right, so that's not that straightforward, again, if it sounds difficult.
Stop right on a piece of paper.
What do you think you should do and then translate that to code?
Good luck.