Getting key value pairs of a dictionary in Julia – pairs() Method
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:
# Julia program to illustrate # the use of pairs() method # Getting an iterator over key =>value # pairs for the specified collection # that maps a set of keys to a set of values. A = [ "a" "c" ; "b" "d" ]; println(pairs(A)) |
chevron_right
filter_none
Output:
Example 2:
# Julia program to illustrate # the use of pairs() method # Getting an iterator over key =>value # pairs for the specified array A = [ "a" "c" ; "b" "d" ]; for (index, value) in pairs(IndexStyle(A), A) println( "$index $value" ) end |
chevron_right
filter_none
Output: