values
values(collection)
Return an iterator over all values in a collection. collect(values(d))
returns an array of values.
Examples
julia> dict = Dict(["one"=> 1, "two"=> 2, "three"=> 3])
values(dict)
ValueIterator for a Dict{ASCIIString,Int64} with 3 entries. Values:
2
1
3
julia> dict = {"A"=>1, "B"=>2, "C"=>3, "D"=>4};
julia> bar = collect(values(dict)) # convert from ValueIterator to Array
4-element Array{Any,1}:
2
1
3
4
julia> reduce(*,bar) # 2 * 1 * 3 * 4
24
julia> foldr(-,bar) # (2 - (1 - (3 - 4)))
0
julia> d = Dict("a" => 1, "b" => 2, "c" => 3)
Dict{String, Int64} with 3 entries:
"b" => 2
"a" => 1
"c" => 3
-
Get values of a dictionary:
julia> collect(values(d)) 3-element Array{Int64,1}: 2 1 3
This example returns an array of all values in the dictionary
d
. -
Iterate over values in a dictionary:
julia> for value in values(d) println(value) end 2 1 3
It shows how to iterate over each value in the dictionary
d
. - Use values to check for specific values:
julia> 2 in values(d) true
It checks if the value
2
exists in the values of the dictionaryd
.
Common mistake example:
julia> values([1, 2, 3])
ERROR: MethodError: no method matching values(::Array{Int64,1})
In this example, the values
function is being used on an unsupported collection type. It's important to note that the values
function is specifically designed for dictionaries (Dict
), so attempting to use it on other collection types will result in an error.
See Also
append!, delete!, deleteat!, empty!, endof, filter, filter!, gc, get!, getkey, haskey, insert!, isempty, keys, map, map!, merge, merge!, pop!, prepend!, push!, reduce, resize!, shift!, splice!, unshift!, values,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.