WolframLang: Association, Get Value

By Xah Lee. Date: . Last updated: .

Get Key's Value by Key

asso[key]

return the value of a key.

Return Missing["KeyAbsent", key] if key missing.

Missing

xx = Association[ "a" -> 3,  "b" -> 2 ]
xx["b"] === 2
xx["c"] === Missing["KeyAbsent", "c"]
Lookup[asso, key]

return the value of key.

If the key missing, return Missing["KeyAbsent", key].

Lookup

xx = Association[ "a" -> 3,  "b" -> 2 ]
Lookup[xx, "b"] === 2
Lookup[xx, "c"] === Missing["KeyAbsent", "c"]
Lookup[asso, key, default]

use default if the key missing.

xx = Association[ "a" -> 3,  "b" -> 2 ];
Lookup[xx, "c", 99] ===  99
Lookup[asso, listOfKeys]

return a list of the values associated with the keys.

Lookup[listOfAssoc, key]

get a list of values of a key, from the list of associations.

Get Key's Value by Index

to get the value by index, just use Part

xx = Association[ "a" -> 3,  "b" -> 2 ]
xx[[1]] === 3

WolframLang, Association (Key Value List)