Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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)

share|improve this question
add comment

1 Answer

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
1  
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
1  
@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
1  
@John, most welcome. May I suggest that you fix the question to reflect this? –  user21 Apr 19 '12 at 14:46
1  
@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
show 4 more comments

Your Answer

 
discard

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.