9951 explained code solutions for 126 technologies


julialangHow to use dictionaries in JuliaLang?


Dictionaries in JuliaLang are used to store key-value pairs. They are created using the Dict constructor. For example:

julia> my_dict = Dict("a" => 1, "b" => 2)
Dict{String,Int64} with 2 entries:
  "a" => 1
  "b" => 2

To access a value, use [ and ]:

julia> my_dict["a"]
1

To add set new value:

julia> my_dict["c"] = 3
Dict{String,Int64} with 3 entries:
  "a" => 1
  "b" => 2
  "c" => 3

To delete a key-value pair, use the pop! function:

julia> pop!(my_dict, "c")
3

julia> my_dict
Dict{String,Int64} with 2 entries:
  "a" => 1
  "b" => 2

Helpful links

Edit this code on GitHub