cancel
Showing results for 
Search instead for 
Did you mean: 

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

nvadithya
New Contributor

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?

1 ACCEPTED SOLUTION

iodwyer
New Contributor II
New Contributor II

 

 

 

 

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 

View solution in original post

3 REPLIES 3

iodwyer
New Contributor II
New Contributor II

 

 

 

 

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 

This is exactly, what I've been looking for, thank you!

BaiChen
New Contributor III

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
q)`a`d
q)