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:


I would like to apply Union on the elements of the list in the following way


The problem Union[list] does not return the desired result when applied on list. Please consider the following example:


The same problem occures with Intersection.

(* Out={{10,2,3},{2,3,4},{2,3,50}} *)

Instead of

(* Out={2,3,4,10,50} *)
share|improve this question
You're looking for Apply? – Rojo Apr 19 '12 at 21:50
Union@Flatten@list – F'x Apr 19 '12 at 21:51
Applyworks. Many thanks – John Apr 19 '12 at 21:52
up vote 9 down vote accepted

You're looking for Apply

Mathematica graphics

Apply[Union, list]

which can be written in short form as

share|improve this answer

Union eliminates duplicate elements in a list, or duplicate sublists in a list of lists.

In[9]:= list = {{a, a, a}, {a, a, a}, {d, e, f}};

Out[10]= {{a, a, a}, {d, e, f}} 

In your example,


even though parts of the sublists are the same, no sublist was a complete duplicate of any other sublist. So there was nothing for Union to do.

share|improve this answer
+1 for the explanation why the OP's example does not behave as expected. – István Zachar Jun 1 '12 at 9:46
Welcome to Mathematica.SE and thanks for taking the time to explain this. Please consider registering your account so your reputation score will be preserved and you can access to more features of the site. – Szabolcs Jun 1 '12 at 9:55

Just stir things up, you can also do the following:


It uses the same function referenced (Map), but makes forces the problem to look like you were expecting:

share|improve this answer

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.