The name of this video is dictionaries lesson. Now, we're going to talk about dictionaries. Dictionaries are the last part of our data structures, and they're really another variable. Like variables, lists, and tuples that we've talked about, they have to adhere to the naming conventions and the no-nos and the things that we covered under variables. So if those were unclear to you, you might want to review them before going through this dictionaries lesson. So dictionaries are a unique data structure, a unique way of saving data. This example, I'm creating a dictionary called timeDict, and I know it's a dictionary because the data that I'm assigning to it are contained within curly brackets. So we use curly brackets to define a dictionary. A dictionary is composed of what are called key value pairs, and this dictionary is showing three key value pairs that are separated by commas. The keys in this case are the strings. So minutes, hours, and days are keys, and 60, 24, and 365 are our values. I have these three key value pairs, and that's how it organizes the data through these key value pairs. It does not organize it through indexing like we see in lists and tuples. So these aren't organized 0, 1, 2, 3 from left to right, I find the values by their keys. But like we talked about with variables and lists and tuples, there is no direct functional correlation between the name of a dictionary and what it holds. That also holds true for the keys that I use. There is no functional relationship between the value that I use and what it's holding. So these are completely made up just like all the other variables. Now, dictionary keys can be a number of different things. They can be variables that hold integers, they can be variables that hold strings, they can be integers themselves. I shouldn't just say integers, I should say numbers. They could also be decimal numbers, and they can be tuples that hold strings and numbers, like we have in that example, and they can be any number of those. So the keys, the number of keys that I have in the tuple, don't have to be equal to the number of values. This is only the key as a reference to whatever that value is. One thing keys cannot be, is they cannot be a list. So that's a no-no, they can't be a list. Keys are not mutable within a dictionary. Values on the other hand can be pretty much anything. They can be mutable forms, and they can be immutable forms, they can be Booleans, they can be strings, they can be tuples, they can be lists, they can be list with nested tuples and nested other lists, they can even be dictionaries themselves. So really values can be almost anything. Now sometimes like with lists, we need to define an empty dictionary. We're going to see that that's going to come in useful when we do iteration using dictionaries. There's two ways to define an empty dictionary. One is to set the dictionary name equal to the Python function dict with parentheses. The other ways to just set it equal to closed curly brackets, which is to me, the preferred method is the method that I use. If we print out both of these dictionaries, we'll see that it amounts to the same thing. So they both create an empty dictionary. Now, once I have an empty dictionary defined, the question is, how do I assign a key value pair to that dictionary? I do that by writing out the dictionary name followed by brackets, closed brackets, so not curly brackets. The curly brackets are used to define the empty dictionary. These brackets are used to define the key. In this case, cat is the key, and then I set it equal to whatever value I want that key to be associated with. What is the key value pair? If I just print out this dictionary, it's going to show me that it holds that one key value pair. If I want to overwrite the value within that dictionary for that particular key, then all I have to do is rewrite that key with the dictionary name and then write in the new value and then that overwrites it. Now if you create a dictionary of some length, and dictionaries can be like lists and tuples can be incredibly long, almost infinitely long, they can hold many key value pairs. But if I print that out, you might be surprised by what you see. It might be in order, it might be out-of-order, it might be something different every time you print it. This is an interesting thing, the order in which the dictionary puts its key value pairs is completely unpredictable. You think that makes it impossible to find something. The order of it doesn't really matter because all that matters in a dictionary is that relationship between a key and a value, and that doesn't change, because that's how I find values within a dictionary by searching the key, so there's no linear order to it at all. There are methods for identifying whether keys or values are actually in a dictionary, which can help if I had a dictionary that was thousands and thousands of key value pairs long. If I want to make sure a key exists within a dictionary, I can use the operator in. So I just say, "Is this key in this dictionary?" This will return either a true or a false. So here it's telling me in the output that it's true, it does exist in that dictionary. You have to do one more step to find whether a value is in a dictionary and then you have to use the Python method values, so writing out the name of the dictionary followed by a period and then values that will return all of the values from that dictionary in a list. Then I can save it in a temperate list called vals, and then I can ask, "Does this value using the operator in, is it in that list vals?" It returns it true or false, and it tells me true if it is. One of the very interesting ways for us in this course to use dictionaries, is with our point matrix structure. We're going to be using them within an iterative loop to create and save point values. It gives us the opportunity to save those point values not just in an endless stream as we would do in a list, but allows us to save it in a matrix C. This is created by the i, j values in the loop and allows us to save it in this dictionary structure. We're going to get into that with a lot of examples. It probably doesn't make sense right now, but it will make sense after we run through a couple of tutorials in the software, you'll see the advantage of it. So that's dictionaries. That's all of the data structures that we're going to work with in this course. I'm looking forward to showing you really the organizational power that they give us within our first 2D point and then 3D point matrices.