Get startedGet started for free

Mixed data types in dictionaries

1. Mixed data types in dictionaries

Working with mixed data types in dictionaries is a critical skill, and it has concepts that we need to focus on individually.

2. Working with nested dictionaries

I mentioned earlier that you can also nest dictionaries to group data or establish a hierarchy. I've reorganized my prior art galleries dictionary to by keyed by zip code and then gallery name with the value of their phone number. I can use the keys() method to see the list of zip code keys. I can print the value of one of those zip codes so you can see the dictionary nested under it,

3. Accessing nested data

and I can get the phone number of one of those galleries by using the gallery name which is the nested dictionary's key as a secondary index. Nesting dictionaries is a very common way to deal with repeating data structures such as yearly data, grouped, or hierarchical data such as organization reporting structures. You access nested values by providing multiple indices to the dictionary or using the get method on an index.

4. Let's practice!

It's your turn to practice!