Union

Union[list1,list2,]

gives a sorted list of all the distinct elements that appear in any of the listi.

Union[list]

gives a sorted version of a list, in which all duplicated elements have been dropped.

Details and Options

  • If the listi are considered as sets, Union gives their union.
  • Union[list1,list2,] can be input in StandardForm and InputForm as list1list2. The character can be entered as un or \[Union].
  • The listi must have the same head, but it need not be List.
  • Union[list1,,SameTest->test] applies test to each pair of elements in the listi to determine whether they should be considered the same.

Examples

open allclose all

Basic Examples  (3)

Give a sorted list of distinct elements:

In[1]:=
Click for copyable input
Out[1]=

Give a sorted list of distinct elements from all the lists:

In[1]:=
Click for copyable input
Out[1]=

Enter using un:

In[1]:=
Click for copyable input
Out[1]=

Scope  (1)

Generalizations & Extensions  (1)

Options  (4)

Applications  (4)

Properties & Relations  (2)

Possible Issues  (1)

See Also

Join  Intersection  Complement  Tally  DeleteDuplicates  BinLists  Split  Or  BitOr

Tutorials

Introduced in 1988
(1.0)
| Updated in 1996
(3.0)