ComenzarEmpieza gratis

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)

Este ejercicio forma parte del curso

Intermediate Julia

Ver curso

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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)
Editar y ejecutar código