Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following:


Now I would like to get the symmetric difference. Hence, the result must be {a,b,e,f,g,h} (whether the result is sorted or not is irrelevant)

BTW: Using Complement[list1,list2,list3] returns {a,b}, since Complement only "gives the elements in e_all which are not in any of the e_i." (Mathematica Documentation Center)

share|improve this question
up vote 8 down vote accepted

I think you are looking for this:

Complement[Join[list1, list2, list3], 
 Intersection[list1, list2, list3]]

or as suggested in the comments:

Complement[Union[list1, list2, list3], 
 Intersection[list1, list2, list3]]

=> {a, b, e, f, g, h}

Note, that the h is present here but not the d. I assume this is a typo in the question.

share|improve this answer
So that's the list of elements that are missing from at least one set. Then h should be in the expected result too. – Szabolcs Apr 19 '12 at 14:30
@Szabolcs, that's a valid point. I have updated the post. – user21 Apr 19 '12 at 14:36
@Szabolcs, I assume that the d<=>h is a typo. We will see what OP has to say. – user21 Apr 19 '12 at 14:40
@John, most welcome. May I suggest that you fix the question to reflect this? – user21 Apr 19 '12 at 14:46
@John With the Join you get duplicates, while with Union you don't. Union is implementation of sum of sets, Join is just a concatenation of lists. – Artes Apr 19 '12 at 14:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.