Search code examples
kdbq-lang

How to get positions of element matches in a list in kdb?


For instance, if I have a list a:2 5 3 1, I can match another list against it, say b:3 5, which matches the 3 at a[2] and the 5 at a[1]. I am interested in getting my hands on the indices 2 1.

I tried where 3 5 in 2 5 3 1 but didn't work.


Solution

  • I think you should use ? for this:

    q)2 5 3 1?3 5
    2 1
    

    http://code.kx.com/q/ref/search/#find