這個pairs()
是 julia 中的一個內置函數,用於返回指定集合的 key=>value 對的迭代器,該集合將一組鍵映射到一組值。這包括數組,其中鍵是數組索引。
用法:
pairs(collection)
or
pairs(IndexStyle(A), A)
參數:
- collection:指定集合。
- IndexStyle(A):指定的迭代器。
- A:指定數組。
返回值:它返回指定集合的 key=>value 對上的迭代器,該集合將一組鍵映射到一組值。
範例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))
輸出:
範例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
輸出:
相關用法
- Julia ceil()用法及代碼示例
- Julia floor()用法及代碼示例
- Julia min()用法及代碼示例
- Julia max()用法及代碼示例
- Julia trunc()用法及代碼示例
- Julia abs()用法及代碼示例
- Julia mod()用法及代碼示例
- Julia round()用法及代碼示例
- Julia axes()用法及代碼示例
- Julia findmin()用法及代碼示例
- Julia parent()用法及代碼示例
- Julia typeof()用法及代碼示例
- Julia collect()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Getting key value pairs of a dictionary in Julia – pairs() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。