WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

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
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Generalizations & Extensions  
Options  
SameTest  
Applications  
Properties & Relations  
Possible Issues  
See Also
Tech Notes
Related Guides
Related Links
History
Cite this Page

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 all close all

Basic Examples  (3)

Give a sorted list of distinct elements:

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

Enter using un:

Scope  (1)

Give a list of the distinct lists:

Generalizations & Extensions  (1)

Union works with any head, not just List :

Options  (4)

SameTest  (4)

Use equivalence classes based on absolute value:

Use equivalence classes based on Floor :

Use Total of list elements:

Use equality of last and first elements:

Applications  (4)

Find divisors that occur in any of 10, 12, and 20:

Find all the triples of bits that occur in the binary decomposition of 10!:

Find the distinct elements in the iteration:

Find what options are used by a list of functions:

Properties & Relations  (3)

Split on the sorted set gives lists of the same elements:

The union is equivalent to the first elements of these lists:

Tally gets the count of identical elements and returns them in the original order:

The union is the sorted list of the elements returned by Tally :

DeleteDuplicates is similar to Union without sorting:

Avoiding the sort improves the speed substantially:

Possible Issues  (1)

For large sets Union may be slow with SameTest since it requires all pairwise comparisons:

When equivalence class representatives can be found, it may be faster to use Union on these:

The results are the same except for the choice of representative:

See Also

Join   Intersection   Complement   SymmetricDifference   Tally   DeleteDuplicates   BinLists   Split   Or   BitOr

Characters: \[Union]

Function Repository: MultisetUnion   MultisetSum

Tech Notes

History

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

Wolfram Research (1988), Union, Wolfram Language function, https://reference.wolfram.com/language/ref/Union.html (updated 1996).

Text

Wolfram Research (1988), Union, Wolfram Language function, https://reference.wolfram.com/language/ref/Union.html (updated 1996).

CMS

Wolfram Language. 1988. "Union." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/Union.html.

APA

Wolfram Language. (1988). Union. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Union.html

BibTeX

@misc{reference.wolfram_2025_union, author="Wolfram Research", title="{Union}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Union.html}", note=[Accessed: 05-December-2025]}

BibLaTeX

@online{reference.wolfram_2025_union, organization={Wolfram Research}, title={Union}, year={1996}, url={https://reference.wolfram.com/language/ref/Union.html}, note=[Accessed: 05-December-2025]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /