RosettaCodeData/Task/Associative-array-Iteration/Julia/associative-array-iteration.julia

20 lines
354 B
Text
Raw Permalink Normal View History

2018-06-22 20:57:24 +00:00
dict = Dict("hello" => 13, "world" => 31, "!" => 71)
2014-01-17 05:32:22 +00:00
# applying a function to key-value pairs:
2018-06-22 20:57:24 +00:00
foreach(println, dict)
2014-01-17 05:32:22 +00:00
# iterating over key-value pairs:
2018-06-22 20:57:24 +00:00
for (key, value) in dict
println("dict[$key] = $value")
2014-01-17 05:32:22 +00:00
end
# iterating over keys:
2018-06-22 20:57:24 +00:00
for key in keys(dict)
@show key
2014-01-17 05:32:22 +00:00
end
# iterating over values:
2018-06-22 20:57:24 +00:00
for value in values(dict)
@show value
2014-01-17 05:32:22 +00:00
end