Getting key value pairs of a dictionary in Julia – pairs() Method
Last Updated :
01 Apr, 2020
The pairs()
is an inbuilt function in julia which is used to return an iterator over key=>value pairs for the specified collection that maps a set of keys to a set of values. This includes arrays, where the keys are the array indices.
Syntax:
pairs(collection)
or
pairs(IndexStyle(A), A)
Parameters:
- collection: Specified collection.
- IndexStyle(A): Specified iterator.
- A: Specified array.
Returns: It returns an iterator over key=>value pairs for the specified collection that maps a set of keys to a set of values.
Example 1:
A = [ "a" "c" ; "b" "d" ];
println(pairs(A))
|
Output:
Example 2:
A = [ "a" "c" ; "b" "d" ];
for (index, value) in pairs(IndexStyle(A), A)
println( "$index $value" )
end
|
Output:
Share your thoughts in the comments
Please Login to comment...