user3203476
user3203476

Reputation: 509

KDB+/Q: how to find all entries in a dictionary matching a certain value?

The find function ? returns the first matching entry in a dictionary for the given value:

q)d:1 2 3 4!100 200 100 400
q)d
1| 100
2| 200
3| 100
4| 400
q)d?100
1
q)

How would I find all the entries in the dictionary matching that value ?

Upvotes: 1

Views: 1333

Answers (2)

Jorge Sawyer
Jorge Sawyer

Reputation: 1341

q)d:1 2 3 4!100 200 100 400
q)where d=100
1 3

Upvotes: 4

shree.pat18
shree.pat18

Reputation: 21757

A naive implementation would be something like this:

f: {(key x) where (y=) value x}
f[d;100] /returns 1 3

Basically, find which indices have the value you are looking for and get the matching keys

Upvotes: 2

Related Questions