Exercise

Create typed dict, iterate

We have created a dictionary to store stock data, but we could have entered any value for the values. As an example, for the key price, we could have entered anything, like a string, or a boolean value. This wouldn't make much sense, so we can use a typed dictionary to restrict the data types that are allowed for both keys and values.

To define a typed dictionary, we first specify the data type for the keys followed by the type for the values, separated by a comma. This is surrounded by curly braces and placed after the Dict keyword.

my_typed_dictionary = Dict{key_datatype, value_datatype}(key => value)

Instructions 1/2

undefined XP
    1
    2
  • Modify the apple_stock_data dictionary so that:
    • keys are constrained by the String data type
    • values are constrained by the Float64 data type