iwelch
1
could I ask for help to translate this julia 0.6 statement to 1.0?
julia> mydict= Dict("One" => 1, "Two" => 2, "Three" => 3);
julia> map( x->(string(x[1], "S") => fill('*', x[2])), mydict)
Dict{String,Array{Char,1}} with 3 entries:
"TwoS" => ['*', '*']
"OneS" => ['*']
"ThreeS" => ['*', '*', '*']
string(x[1],"S")
creates the left side of the pair, the fill creates the right side of the pair, and I want to iterate over every item in the dict.
1 Like
iwelch
2
figured it out:
julia> Dict( string(key,"S") => fill("*", value) for (key, value) in mydict)
Dict{String,Array{String,1}} with 3 entries:
"OneS" => ["*"]
"ThreeS" => ["*", "*", "*"]
"TwoS" => ["*", "*"]
1 Like
quinnj
3
You could also map over pairs(dict)
.
iwelch
4
is this so? pairs(mydict)
does not seem to do anything
julia> mydict
Dict{String,Int64} with 3 entries:
"One" => 1
"Two" => 2
"Three" => 3
julia> pairs(mydict)
Dict{String,Int64} with 3 entries:
"One" => 1
"Two" => 2
"Three" => 3
1 Like
Using collect(dict)
seems to do the trick.