Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

export keys and values of dictionary as variable name and value

Tags:

julia

How could I create variables from keys and values of a dictionary? Is the following extract (like PHP) possible?

julia> d = Dict(
    "key1"    =>111,
    "key2"    =>222,
    "key3"    =>333
);
julia> extract(d)
julia> key1, key2, key3
(111,222,333)
like image 720
Phuoc Avatar asked Dec 04 '25 11:12

Phuoc


1 Answers

k = collect(keys(d)) 

v = collect(values(d)) 

Both keys and values return iterators. collect then produces an array.

But note that you often do not need to do this and can just iterate through the dictionary using

for (k, v) in d
like image 126
David P. Sanders Avatar answered Dec 07 '25 22:12

David P. Sanders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!