Related Articles

Related Articles

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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


Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :