diff --git a/base/dict.jl b/base/dict.jl index 0bc02b6a9a54e5..918863d2336ad9 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -59,7 +59,7 @@ Given a single iterable argument, constructs a [`Dict`](@ref) whose key-value pa are taken from 2-tuples `(key,value)` generated by the argument. # Examples -```jldoctest +```jldoctest dictexamples julia> Dict([("A", 1), ("B", 2)]) Dict{String,Int64} with 2 entries: "B" => 2 @@ -68,7 +68,7 @@ Dict{String,Int64} with 2 entries: Alternatively, a sequence of pair arguments may be passed. -```jldoctest +```jldoctest dictexamples julia> d = Dict("A"=>1, "B"=>2) Dict{String,Int64} with 2 entries: "B" => 2 @@ -76,7 +76,7 @@ Dict{String,Int64} with 2 entries: ``` After creation of a Dict you can use `d[x]` for getting the values and `d[x]=y` for changing the values. -```jldoctest +```jldoctest dictexamples julia> d["A"] 1 @@ -86,7 +86,7 @@ julia> d["B"] = 3 You can use [Generator](https://docs.julialang.org/en/v1/manual/arrays/#Generator-Expressions-1) and [Comprehension][https://docs.julialang.org/en/v1/manual/arrays/#Comprehensions-1] syntax to create dictionaries: -```jldoctest +```jldoctest dictexamples julia> Dict(x => x^2 for x = 0:1:4) Dict{Int64,Int64} with 5 entries: 0 => 0 @@ -99,7 +99,7 @@ Dict{Int64,Int64} with 5 entries: You can also create and fill dictionaries dynamically (will be slower than the other ways). First, you need to create an empty dictionary using: -```jldoctest +```jldoctest dictexamples julia> Dict{Int64,Any}() # type specified Dict{Int64,Any} with 0 entries @@ -108,16 +108,14 @@ Dict{Any,Any} with 0 entries ``` After creating an empty dictionary, you can fill it via a for loop: -```jldoctest +```jldoctest dictexamples mydict = Dict{Int64,Any}() animals = ["cat", "fish", "elephant"] for (i, x) in enumerate(animals) mydict[i] = [x, length(x)] end -``` -```jldoctest julia> mydict Dict{Int64,Any} with 3 entries: 2 => Any["fish", 4] diff --git a/doc/src/base/collections.md b/doc/src/base/collections.md index 8b5681b12bbf43..5bda433c94c0ab 100644 --- a/doc/src/base/collections.md +++ b/doc/src/base/collections.md @@ -189,8 +189,9 @@ Dictionaries may also be created with generators. For example, `Dict(i => f(i) f Given a dictionary `D`, the syntax `D[x]` returns the value of key `x` (if it exists) or throws an error, and `D[x] = y` stores the key-value pair `x => y` in `D` (replacing any existing value -for the key `x`). Multiple arguments to `D[...]` are converted to tuples; for example, the syntax -`D[x,y]` is equivalent to `D[(x,y)]`, i.e. it refers to the value keyed by the tuple `(x,y)`. +for the key `x`). + +Multiple arguments to `D[...]` are converted to tuples; for example, the syntax `D[x,y]` is equivalent to `D[(x,y)]`, i.e. it refers to the value keyed by the tuple `(x,y)`. ```@docs Base.AbstractDict