# Symmetric difference of a sample of lists

Consider the following:

list1={a,b,c,d};
list2={c,d,e,f};
list3={g,d,c,h};


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)

-

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.

-
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