Lookup
✖
Lookup
Details

- In Lookup[assoc,key,default], default is only evaluated if key is not found in assoc.
- Lookup can be applied not only to Association objects, but also to lists of rules.
- Lookup[assoc,Key[list]] treats the list list as a single key rather than a list of keys.
- Lookup[{assoc1,assoc2,…},{key1,key2,…}] gives an array of the form {{assoc1[key1],assoc1[key2],…},…}.
- Lookup[key][assoc] is equivalent to Lookup[assoc,key].
Examples
open allclose allBasic Examples (4)Summary of the most common use cases
Look up the value associated with the key:

https://wolfram.com/xid/0en0smxcs-hj0p16

When a key is not found, a Missing object is returned by default:

https://wolfram.com/xid/0en0smxcs-o9yps4

Provide a default value to be used when the key is not found:

https://wolfram.com/xid/0en0smxcs-7yl7rj

Use the operator form of Lookup:

https://wolfram.com/xid/0en0smxcs-9qoeif

Scope (5)Survey of the scope of standard use cases
Look up multiple keys at once:

https://wolfram.com/xid/0en0smxcs-wtc1wb

Lookup threads over lists of associations:

https://wolfram.com/xid/0en0smxcs-03ovj1

https://wolfram.com/xid/0en0smxcs-e6mqiz

Query multiple keys from multiple associations:

https://wolfram.com/xid/0en0smxcs-n9iih8

Lookup can be used to look up keys in lists of rules:

https://wolfram.com/xid/0en0smxcs-ftbz83


https://wolfram.com/xid/0en0smxcs-rofjol

Wrap the result in Hold to prevent it from evaluating:

https://wolfram.com/xid/0en0smxcs-b94q59

Apply the operator form to a list of lists:

https://wolfram.com/xid/0en0smxcs-erqs0v

Applications (1)Sample problems that can be solved with this function
You can use constructs such as Throw and Return in the third argument of Lookup to abort a computation when a required key is missing:

https://wolfram.com/xid/0en0smxcs-1a7q2p

https://wolfram.com/xid/0en0smxcs-221kgk


https://wolfram.com/xid/0en0smxcs-i0jj16

Properties & Relations (4)Properties of the function, and connections to other functions
When the key is present, the default is not evaluated:

https://wolfram.com/xid/0en0smxcs-6cpkt8

Even when it appears in a result multiple times, the default value is only evaluated once:

https://wolfram.com/xid/0en0smxcs-z1ft8x


https://wolfram.com/xid/0en0smxcs-bln5nt

Applying an association to a key is typically equivalent to using Lookup on that key:

https://wolfram.com/xid/0en0smxcs-29gmcm


https://wolfram.com/xid/0en0smxcs-mbwbkc

Lists are handled differently by Lookup, however:

https://wolfram.com/xid/0en0smxcs-cnuwsv


https://wolfram.com/xid/0en0smxcs-u85ubd

Wrap the list in Key to make Lookup treat it as a single key:

https://wolfram.com/xid/0en0smxcs-x8krv0

Lookup automatically strips up to one level of Key from its second argument:

https://wolfram.com/xid/0en0smxcs-ctc191

https://wolfram.com/xid/0en0smxcs-85c0w


https://wolfram.com/xid/0en0smxcs-mwwvvr

Similarly, lists of keys are stripped of any Key wrappers they contain:

https://wolfram.com/xid/0en0smxcs-bidudk

This stripping allows looking up expressions of the form Key[{…}] and Key[Key[…]]:

https://wolfram.com/xid/0en0smxcs-xqi46m


https://wolfram.com/xid/0en0smxcs-sfytvo

Possible Issues (1)Common pitfalls and unexpected behavior
When the key to be looked up is a list or an expression with head Key, it must be wrapped in a Key to avoid ambiguity:

https://wolfram.com/xid/0en0smxcs-lakk1l


https://wolfram.com/xid/0en0smxcs-9q0ti7


https://wolfram.com/xid/0en0smxcs-mgl91y


https://wolfram.com/xid/0en0smxcs-ssoute


https://wolfram.com/xid/0en0smxcs-mkiser

Wolfram Research (2014), Lookup, Wolfram Language function, https://reference.wolfram.com/language/ref/Lookup.html (updated 2020).
Text
Wolfram Research (2014), Lookup, Wolfram Language function, https://reference.wolfram.com/language/ref/Lookup.html (updated 2020).
Wolfram Research (2014), Lookup, Wolfram Language function, https://reference.wolfram.com/language/ref/Lookup.html (updated 2020).
CMS
Wolfram Language. 2014. "Lookup." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/Lookup.html.
Wolfram Language. 2014. "Lookup." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/Lookup.html.
APA
Wolfram Language. (2014). Lookup. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Lookup.html
Wolfram Language. (2014). Lookup. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Lookup.html
BibTeX
@misc{reference.wolfram_2025_lookup, author="Wolfram Research", title="{Lookup}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/Lookup.html}", note=[Accessed: 24-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_lookup, organization={Wolfram Research}, title={Lookup}, year={2020}, url={https://reference.wolfram.com/language/ref/Lookup.html}, note=[Accessed: 24-March-2025
]}