MySQL: difference of two result sets

To perform result1 – result2, you can join result1 with result2, and only output items that exist in result1. For example: SELECT DISTINCT result1.column FROM result1 LEFT JOIN result2 ON result1.column = result2.column WHERE result2.column IS NULL In set theory terms this is a set difference of result1 and result2, i.e. elements in result1 but … Read more

Get difference between two lists with Unique Entries

To get elements which are in temp1 but not in temp2 (assuming uniqueness of the elements in each list): In [5]: list(set(temp1) – set(temp2)) Out[5]: [‘Four’, ‘Three’] Beware that it is asymmetric : In [5]: set([1, 2]) – set([2, 3]) Out[5]: set([1]) where you might expect/want it to equal set([1, 3]). If you do want set([1, 3]) … Read more

Difference and intersection of two arrays containing objects

You could define three functions inBoth, inFirstOnly, and inSecondOnly which all take two lists as arguments, and return a list as can be understood from the function name. The main logic could be put in a common function operation that all three rely on. Here are a few implementations for that operation to choose from, … Read more

c++ STL set difference

Yes there is, it is in <algorithm> and is called: std::set_difference. The usage is: #include <algorithm> #include <set> #include <iterator> // … std::set<int> s1, s2; // Fill in s1 and s2 with values std::set<int> result; std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(), std::inserter(result, result.end())); In the end, the set result will contain the s1-s2.