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)
This exercise is part of the course
Intermediate Julia
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a typed dictionary with keys as String and values as Float64
apple_stock_data = Dict____("price" => 131.86, "prev_close" => 131.99, "volume" => 55000000)