El miércoles, 27 de agosto de 2014 11:40:39 UTC-5, Philip Thomas escribió:
>
>
> I'm a little confused by the Dict() documentation because it does not seem 
> to cover pushing items to a dict. 
>
> How would I initialize a dict of size n using *sizehint* then push 
> key/value pairs to it?
>
> The pythonic syntax of syntax of dict["foo"] = "bar" seems to throw an 
> exception, and push!() doesn't make pushing key/value pairs clear. 
>
>
The following works for me on 0.3:

julia> d = ["H"=>1]
Dict{ASCIIString,Int64} with 1 entry:
  "H" => 1

julia> push!(d, "He", 2) 
Dict{ASCIIString,Int64} with 2 entries:
  "He" => 2
  "H"  => 1

The last line is equivalent to just saying d["He"]=2.

 

> Dict documentation:
> http://julia.readthedocs.org/en/latest/stdlib/base/#Base.Dict
>
> Thanks!
>

Reply via email to