Is there an `outer` or `exclusive or` operator equivalent to `inter` in KDB?

Viewed 738

Let's say I have the following two lists:

 x : `a`b`c`d;
 y : `a`b`e`f;

For the intersection, there is the inter operator:

q)x inter y
`a`b

Is there a similar operator to do the EXCLUSIVE OR such that I would get:

q)x outer y
`c`d`e`f

?

2 Answers

the operation except will give you elements of one list that do not belong in another.

However in your case x except y would only give `c`d and y except x would only give `e`f.

Therefore you could use either;

q)(x except y),y except x
`c`d`e`f

or

q)(x union y) except (x inter y)
`c`d`e`f

or alternatively without using except

q)where(count each group (distinct x), distinct y)=1
`c`d`e`f

if you want to get a list of all exclusive elements.

Regards, Kevin

From Kevin's answers, the first will give duplicates if they are present in either, the last will give the distinct list. To use the function infix as you have requested, you need to define the function in the .q namespace

q).q.outer:{(x union y) except (x inter y)}
q)x outer y
`c`d`e`f
Related