Working with Dictionaries
Dictionaries store data as key-value pairs, like a real dictionary where you look up a word (key) to find its definition (value). They're perfect for financial data where you want to associate values with meaningful labels.
Creating Dictionaries
Loading Python Playground...
Accessing Dictionary Values
Use keys to retrieve values:
Loading Python Playground...
Modifying Dictionaries
Loading Python Playground...
Useful Dictionary Methods
Loading Python Playground...
Nested Dictionaries
Dictionaries can contain other dictionaries - perfect for portfolios:
Loading Python Playground...
Looping Through Dictionaries
Loading Python Playground...
Practice: Create a Stock Dictionary
Loading Python Exercise...
Practice: Calculate Gain/Loss
Loading Python Exercise...
Key Takeaways
- Dictionaries store data as
{key: value}pairs - Access values with
dict['key']ordict.get('key') - Use
.get()with a default value to avoid errors - Add/update values with
dict['key'] = value - Delete with
del dict['key'] - Loop with
for key, value in dict.items() - Dictionaries can be nested for complex data structures
- Perfect for storing labeled financial data
Next, we'll put it all together and build your first financial calculator!

