Associative array/Iteration: Difference between revisions

Content added Content deleted
No edit summary
Line 1,448: Line 1,448:


=={{header|Julia}}==
=={{header|Julia}}==
{{trans|Python}}
{{works with|Julia|0.6}}
<lang julia>mydict = [ "hello"=>13, "world"=>31, "!"=>71 ]
<lang julia>dict = Dict("hello" => 13, "world" => 31, "!" => 71)


# applying a function to key-value pairs:
# applying a function to key-value pairs:
map(println, mydict);
foreach(println, dict)


# iterating over key-value pairs:
# iterating over key-value pairs:
for (key,value) in mydict
for (key, value) in dict
println("key = $key, value = $value")
println("dict[$key] = $value")
end
end


# iterating over keys:
# iterating over keys:
for key in keys(mydict)
for key in keys(dict)
println("key = $key")
@show key
end
end


# iterating over values:
# iterating over values:
for value in values(mydict)
for value in values(dict)
println("value = $value")
@show value
end</lang>
end
</lang>

{{out}}
{{out}}
<pre>
<pre>