[MUSIC] How are you feeling so far? Lists and strings are pretty cool, right? These tools let us do a ton of neat stuff in our code so they can be super fun to experiment with. We're now going to learn about another data type, dictionaries. Like lists, dictionaries are used to organize elements into collections. Unlike lists, you don't access elements inside dictionaries using their position. Instead, the data inside dictionaries take the form of pairs of keys and values. To get a dictionary value we use its corresponding key. Another way these two vary is while in a list the index must be a number, in a dictionary you can use a bunch of different data types as keys, like strings, integers, floats, tuples, and more. The name dictionaries comes from how they work in a similar way to human language dictionaries. In an English language dictionary the word comes with a definition. In the language of a Python dictionary, the word would be the key and the definition would be the value. Make sense? Let's check out an example. You can create an empty dictionary in a similar way to creating an empty list, except instead of square brackets dictionaries use curly brackets to define their content. Once again, we can use the type function to check that the variable we've just created is a dictionary x = {} type(x). Creating initialized dictionaries isn't too different from the syntax we used in earlier videos to create initialized lists or tuples. But instead of a series of slots with values in them, we have a series of keys that point at values. Okay, let's check out an example dictionary. We'll call it file_counts = and then {"jpeg":10, "txt":14, "csv":2, "py":}23 print(file_counts). In this file_counts dictionary, we've stored keys that are strings, like jpg, that point at integer values, like 10. When creating the dictionary we use colons and between the key and the value and separate each pair by commas. In a dictionary, it's perfectly fine to mix and match the data types of keys and values like this and can be very useful. In this example, we're using a dictionary to store the number of files corresponding to each extension. It makes sense to encode the file extension formatting in a string, while it's natural to represent a count as an integer number. Let's say you want to find out how many text files there are in the dictionary. To do this, you would use the key txt to access its associated value. The syntax to do this may look familiar, since we used something similar in our examples of indexing strings, lists, and tuples. File_counts ["txt"]. You can also use the in keyword to check if a key is contained in a dictionary. Let's try a couple of keys. "jpg" in file_counts, True. "html" in file_counts, False. Dictionaries are mutable. You might remember what mutable means from an earlier video. That's right, it means we can add remove and replace entries. To add an entry in a dictionary, just use the square brackets to create the key and assign a new value to it. Let's add a file count of eight for a new CFG file extension and dictionary. file_counts ["cfg"] = 8 and then print(file_counts). This brings up an interesting point about dictionaries. What do you think will happen if we try to add a key that already exists in the dictionary? file_counts["csv"] = 17, print(file_counts). When you use a key that already exists to set a value, the value that was already paired with that key is replaced. As you can see in this example, the value associated with the csv key used to be 2, but it's now 17. The keys inside of a dictionary are unique. If we try to store two different values for the same key, we'll just replace one with the other. Last off, we can delete elements from a dictionary with the del keyword by passing the dictionary and the key to the element as if we were trying to access it. del file_counts["cfg"] and print(file_counts). What do you think? Dictionaries seem pretty useful, right? We've now seen how to create a dictionary and how to add, modify, and delete elements stored in the dictionary. Up next, we'll discover some interesting things we can do with them.