00:00 Values of dictionaries can have any valid Python type. That means a dictionary item can have another dictionary as its value. Just as you can nest lists inside other lists and tuples inside other tuples, you can create nested dictionaries. On the right side, you can see the capitals dictionary, but I altered the dictionary to illustrate the idea of a nested dictionary.
print(state["Texas"]—it’s important here that you use the capital T for
"Texas" because dictionary keys are case-sensitive—and after that, another square bracket with
"capital", which is a key of the nested dictionary.
03:18 Nesting dictionaries might look a bit complicated even if you don’t run into errors, but nested dictionaries come up more often than you might expect. They’re particularly useful when working with data transmitted over the Web.
03:33 Nested dictionaries are also great for modeling structured data such as spreadsheets or relational databases. And like with any data structure or basically anything in Python, the more you use it, the more you get used to it.
Become a Member to join the conversation.