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 use constructors in JuliaLang?
- How to use enums in JuliaLang?
- How to work with linear algebra in JuliaLang?
- How to use the map function in JuliaLang?
- How to get JuliaLang version?
- How to test code in JuliaLang?
- How to work with CSV in JuliaLang?
- How to use addprocs in JuliaLang?
- How to append to an array in JuliaLang?
- How to use regular expressions in JuliaLang?
See more codes...