The Opposite of Intersect()

The opposite of Intersect()

As stated, if you want to get 4 as the result, you can do like this:

var nonintersect = array2.Except(array1);

If you want the real non-intersection (also both 1 and 4), then this should do the trick:

var nonintersect = array1.Except(array2).Union( array2.Except(array1));

This will not be the most performant solution, but for small lists it should work just fine.

Opposite of set.intersection in python?

You are looking for the symmetric difference; all elements that appear only in set a or in set b, but not both:

a.symmetric_difference(b)

From the set.symmetric_difference() method documentation:

Return a new set with elements in either the set or other but not both.

You can use the ^ operator too, if both a and b are sets:

a ^ b

while set.symmetric_difference() takes any iterable for the other argument.

The output is the equivalent of (a | b) - (a & b), the union of both sets minus the intersection of both sets.

Opposite of INTERSECT in Oracle

If both select1 and select2 return no duplicates, you can use something like this:

SELECT * FROM (select1 UNION ALL select2) a
GROUP BY a.col1, a.col2, ...
HAVING count(*) = 1

Function to find symmetric difference (opposite of intersection) in R?

Why not:

sym_diff <- function(a,b) setdiff(union(a,b), intersect(a,b))

SQL Server Difference (opposite of intersect)

How about something like this?

SELECT A, B FROM Table1 EXCEPT SELECT A,B FROM Table2
UNION
SELECT A, B FROM Table2 EXCEPT SELECT A,B FROM Table1

Here is an example with the FULL OUTER JOIN method (assuming A is not nullable in both tables)

SELECT IsNull(Table1.A, Table2.A) a,IsNull(Table1.B, Table2.B) B
FROM Table1
FULL OUTER JOIN Table2 ON (Table1.A=Table2.A AND Table1.B=Table2.B)
WHERE Table1.A is null or Table2.A is null

Haskell opposite of intersect (List)

You're looking for set difference, which is the \\ operator from Data.List:

Prelude> import Data.List ((\\))
Prelude Data.List> let all = [1..5]
Prelude Data.List> let mask = [2,3]
Prelude Data.List> all \\ mask
[1,4,5]

Opposite of array_intersect?

That sounds like a job for array_diff.

Returns an array containing all the
entries from array1 that are not
present in any of the other arrays.

Opposite of intersect in groovy collections

You probably want to combine both the answers from @Andre and @denis

I think what you want is the union and then subtract the intersection from this

def a = [1,2,3,4,5]
def b = [2,3,4]

assert [1,5] == ( a + b ) - a.intersect( b )

The solution given by denis would depend on whether you do

def opposite = leftCollection-rightCollection // [1,5]

or

def opposite = rightCollection-leftCollection // []

which I don't think you wanted

What's the opposite of the intersect function in OrientDB?

Ok i find what was missing !

I have to compare on @rid :

SELECT difference(in("Regroupe").in("Obligatoire").out("Pertinent").@rid, out("Pertinent").@rid) FROM #89:50

Opposite of array_intersect

No there isn't builtin for that

I believe a language will never provide such a builtin function



Related Topics



Leave a reply



Submit