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
More of Julialang
- How to test code in JuliaLang?
- How to round numbers in JuliaLang?
- How to get JuliaLang version?
- How to use tuples in JuliaLang?
- How to use the JuliaLang package manager?
- How to install JuliaLang?
- How to solve differential equations in JuliaLang?
- How to use try catch in JuliaLang?
- How to use regular expressions in JuliaLang?
- How to calculate the mean in JuliaLang?
See more codes...