12.7 Lists as Sets
Mathematica TE usually keeps the elements of a list in exactly the order you originally entered them. If you want to treat a Mathematica TE list like a mathematical set, however, you may want to ignore the order of elements in the list.
Set theoretical functions.
Union gives the elements that occur in any of the lists.
In[1]:= Union[{c, a, b}, {d, a, c}, {a, e}]
Out[1]=
You can use Union to remove duplicates from a single list.
In[2]:= Union[{a, b, a, b, c, a}]
Out[2]=
Intersection gives only elements that occur in all the lists.
In[3]:= Intersection[{a, c, b}, {b, a, d, a}]
Out[3]=
Complement gives elements that occur in the first list, but not in any of the others.
In[4]:= Complement[{a, b, c, d}, {a, d, e}]
Out[4]=