Key value pairs in dictionary, and how to retrieve them given one?

https://learninghub.kx.com/forums/topic/key-value-pairs-in-dictionary-and-how-to-retrieve-them-given-one

I’m wondering on how to retrieve the key given the value of a dictionary?

The way to get value given the key is

array[key] - this will output the value, but what if I have the value and am looking to get the key?

 

q)d:`a`b`c!1 2 3 
q)d[`a] 
1 
q)d?1 
`a 
q)d:`a`b`c`d!1 2 3 1 
q)d?1 
`a

be mindful, with this method and duplicate values, only the first key is returned

you also can use where clause, which return all keys that have duplicates:

q)dic:`a`b`c`d!1 2 3 1
q)where dic=1
`a`d