Back to Lookup By Value

Dictionaries · Lookup By Value · Practice Question

Extract the first key by value

Sign in to track your progress

Question

Given the dictionary:

dict:`a`b`c`d`e!2 3 4 5 3

Extract the first key whose value is 3.

Solution

first where dict = 3

dict = 3 produces the boolean dictionary `a`b`c`d`e!01001b; where returns the matching keys `b`e; first takes `b.

Alternative Solution

dict ? 3

Find (?) returns the key of the first matching value directly — more concise for an exact-value lookup, but it doesn't generalise to a predicate like first where dict > 3.