How can one get all the keys of a dictionary as a separate array in Julia.
For example:
Dict("a" => 123, "b" => 456, "c" => 789)
would give the following Array:
["a", "b", "c"]
Here is how you can do it (if an iterator is enough for you just use keys to avoid materializing the array):
julia> d = Dict("a" => 123, "b" => 456, "c" => 789)
Dict{String, Int64} with 3 entries:
"c" => 789
"b" => 456
"a" => 123
julia> keys(d)
KeySet for a Dict{String, Int64} with 3 entries. Keys:
"c"
"b"
"a"
julia> collect(keys(d))
3-element Vector{String}:
"c"
"b"
"a"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With