28 lines
982 B
Plaintext
28 lines
982 B
Plaintext
julia> hash = {'a' => 97, 'b' => 98} # list keys/values
|
|
{'a'=>97,'b'=>98}
|
|
|
|
julia> hash = {c => int(c) for c = 'a':'d'} # dict comprehension
|
|
{'a'=>97,'c'=>99,'b'=>98,'d'=>100}
|
|
|
|
julia> hash['é'] = 233 ; hash # add an element
|
|
{'a'=>97,'c'=>99,'b'=>98,'é'=>233,'d'=>100}
|
|
|
|
julia> hash = Dict() # create an empty dict
|
|
Dict{Any,Any}()
|
|
|
|
julia> for c = 'a':'d' hash[c] = int(c) end ; hash # fill it
|
|
{'a'=>97,'c'=>99,'b'=>98,'d'=>100}
|
|
|
|
julia> hash = (Char=>Int64)['a' => 97, 'b' => 98] # create a typed dict
|
|
['a'=>97,'b'=>98]
|
|
|
|
julia> hash["a"] = 1 # type mismatch
|
|
ERROR: no method convert(Type{Char}, ASCIIString)
|
|
in setindex! at dict.jl:533
|
|
|
|
julia> hash = Dict(['a','b','c'], [97,98,99]) # constructor
|
|
['a'=>97,'c'=>99,'b'=>98]
|
|
|
|
julia> typeof(hash) # type is infered correctly
|
|
Dict{Char,Int64} (constructor with 3 methods
|