 Hello, hello, hello. Wait on. Just testing, testing to see what am I actually reporting. Thank you. Hello, this is Dr. Jeffries. In this video, we'll be learning about Python dictionaries and how we can work with them. This allows us to work with key value pairs. When I say we'll be working with key value pairs, these are two linked values where the key is a unique identifier, where we can find our data. And the value is that data. So we can actually think of it almost like a real physical dictionary, where we look up definitions. So in that example, each word that we look up will be the key and the definition of that word will be the value. So let's go ahead and look at some examples and how we want to represent dictionaries. Go ahead and take a look at some examples. So in order to define a dictionary, you just basically use these curly brackets. And that defines our dictionary. Right now, that's just an empty dictionary. But so in order to put some variables in there, I'll say a key of name, separate that by colon. And then we can go in there and say, John, say we want to go put another key in, maybe age, age colon, let's see, age colon, 24, let's go 18 to separate the by another comma, let's say class, class, let's say what, cryptography. OK, so this is our definition, our dictionary that we've just defined. Adding, let's print out our student. And as you can see, we've got the name John, age, 18, class, cryptography. All right? So if we save that and run it, we can see that it prints out all of our keys. Let's just get a value of one key so we can add square brackets after our dictionary name and specify the key that we want to access. We can also print anything else that we want from that dictionary. Let's put in the other key, brackets, let's say age, run that. OK, I'll say we wanted to maybe add another item to our dictionary. We would simply just say student, and if we want to add that, say maybe a bracket, see class, what else could we add here? I'm going to say if we wanted to see maybe a block it. OK, so then if we can do the print student again. You see there with block C has been added to our dictionary. So let's say I wanted to overwrite something. So say I wanted to change that name, student name equals Susan, OK? Overwriting that, again, we now look at our dictionary. Again, we'll see that the name John has been overwritten by Susan to certain things. So here we're printing the entire dictionary. But I could also just print the name, put that in brackets within there, and then I prints out the name. So just that particular key in the dictionary itself. Now, if you try to print something that does not exist, we will get an error. So let's say I said print student Greg, OK? Well, Greg does not exist in our dictionary. So we'll get this trace back error of Greg. One other thing to note here is that the values can be any type. But the keys can only be certain types. And there are different types we can use for that. But most commonly the keys are strings or numbers. So in Python, you can even mix the different types of keys. So let's say we want to add a new key, 10, with the value of 102. So let's go in and write our brackets here. So let's say student 10 equals 100. OK, so then if we print student again, see that we'll have that 100 is in there. But that kind of comes in handy if you want to say start adding actual CSS student 1 equals the actual word 1, right? Student 2 equals the word 2, something we want to do adding to our dictionary itself. OK, so now we go do a little print. Print student, see we've got 1 and we've got 2. So many things you can do with dictionaries with respect to the different types of key values. Going back to this here where we printed out, we tried to find an actual key that was not in the dictionary and we got an error value because it didn't exist. Well, we may not always want to throw an error. We just want to return none or default value. So to do that, we can use the dictionaries get method. So instead of accessing this key like we tried to do here, we can use the get method and get the name. And so if that key already exists, let's just try to go ahead and get something that we know does exist. So let's see, if I get a name, then that'll return Susan. But let's say we go and try to get something that we know does not exist. What that will return? Let's say, let's go get the, so if I go try and get that value that doesn't exist, then that method returns an error, returns none instead of an error. We can also specify default value for keys that don't exist. So we can just pass that default value as a second argument to the method. So if we put a comma here and a string, let's see here what we get. If I go here and say print student dot get, Greg, and let's just say I want to return a value of C. Let's say not found. So now when we run that cell, then the method returns not found. So that's a good way to give some more meaning to our error type of messages. Some other operations that we can do on dictionaries. Let's retype our dictionary here so we know what we have. So if you wanted to delete an item, delete a key. So we go delete student. The name. All right, we print that student a dictionary again. You see that name and its associated value are no longer in the dictionary. OK, so we want to get the length of a dictionary. So let's go length dictionary here. Boom. We get six. Why six? Well, the one, two, three, four, five, six items in the dictionary. All right. So say we want to see if an item is in the dictionary. So the way we would do that is. Oh, we type in Susan and students. So we want to know is this Susan in the dictionary student? No, because remember we had taken Susan out of there. Well, let's see. Let's go check for something that's actually in there. So let's go cryptography, cryptography, and student. That should return a true. No? The reason why that's false is cryptography is in the dictionary. However, cryptography is a value. We check membership. It only looks for keys. So if I wanted to see membership, I would have to say class, right? Class is the key student. And that should give us return us a value of true, because that indeed is in the dictionary student. And say you want to delete all the items from the dictionary. So we would just use the clear method. And that should clear it out. Print student, see what we get here. Nothing. It's the empty. An empty dictionary. And if we just wanted to get rid of that dictionary altogether, then we would just say delete event. And now we should definitely get an error message because there is no longer a dictionary by the name of student. Yep, not defined. So there's a few things about dictionaries that we'll be utilizing and going forward in the course. But for now, dictionaries are going to be very useful, or we can go and look at our key value pairs of things that we may want to utilize in our cryptography endeavors. That's it for now. We will talk to you soon.