KDB+/Q: How does one select all items (keys+values) of a dictionary where the respective value conforms to a condition?

Viewed 990

How does one filter the items of a dictionary based on the values therein. For instance, given the following dictionary:

990.5| 0
900.5| 0
600.5| 300
600  | -300

How does one filter out all instances therein where the value = 0. The result thereafter being:

600.5| 300
600  | -300

Thanks

2 Answers

Here's one way of doing it.

q)d: 990.5 900.5 600.5 600 ! 0 0 300 -300
q)k ! d k: where d <> 0
600.5| 300
600  | -300

The where keyword can also be used to achieve this without assignment

q)d:990.5 900.5 600.5 600!0 0 300 -300
q)where[d<>0]#d
Related