WolframLang: Association, Get Value

By Xah Lee. Date: .

Get Key's Value

assoc[key]
return the value of a key. Return Missing["KeyAbsent", key] if key no exist. Missing

Lookup[assoc, key]
return the value of key.

If the key no exist, return Missing["KeyAbsent", key].

Lookup
xx = Association[ a -> 3,  b -> 2 ];

Lookup[xx, b] === 2

Lookup[xx, c] === Missing["KeyAbsent", c]
Lookup[assoc, key, default]
gives default if the key no exist.
xx = Association[ a -> 3,  b -> 2 ];

Lookup[xx, c, 99] ===  99
Lookup[assoc, {key1, key2 etc}]
return a list of the values associated with the keys.
Lookup[{assoc1, assoc2 etc}, key]
get a list of values of a key, from the list of associations .

WolframLang: Association (Key Value Pairs)

WolframLang in Depth

Basics

Comment, Print

String

Arithmetic

List

Expression, Atom, Head

Boolean

Conditional

Variable

Loop

Data Structure

Function

Pattern Matching

Advanced

Shell Tasks

Misc