PRODUCTS
Products Overview
Mathematica
Mathematica for Students
Mathematica Home Edition
Wolfram
CDF Player
(free download)
Computable Document Format (CDF)
web
Mathematica
grid
Mathematica
Wolfram
Workbench
Wolfram
Finance Platform
Mathematica
Add-Ons
Wolfram|Alpha Products
SOLUTIONS
Solutions Overview
Engineering
Aerospace Engineering & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Materials Science
Mechanical Engineering
Operations Research
Optics
Petroleum Engineering
Biotechnology & Medicine
Bioinformatics
Medical Imaging
Finance, Statistics & Business Analysis
Actuarial Sciences
Data Analysis & Mining
Econometrics
Economics
Financial Engineering & Mathematics
Financial Risk Management
Statistics
Software Engineering & Content Delivery
Authoring & Publishing
Interface Development
Software Engineering
Web Development
Science
Astronomy
Biological Sciences
Chemistry
Environmental Sciences
Geosciences
Social & Behavioral Sciences
Design, Arts & Entertainment
Game Design, Special Effects & Generative Art
Education
STEM Education Initiative
Higher Education
Community & Technical College Education
Primary & Secondary Education
Students
Technology
Computable Document Format (CDF)
High-Performance & Parallel Computing (HPC)
See Also: Technology Guide
PURCHASE
Online Store
Other Ways to Buy
Volume & Site Licensing
Contact Sales
Software
Service
Upgrades
Training
Books
Merchandise
SUPPORT
Support Overview
Knowledge Base
Learning Center
Community & Forums
Training
Does My Site Have a License?
Wolfram User Portal
COMPANY
About Wolfram Research
News & Events
Wolfram Blog
Partnerships
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
All Sites
Wolfram|Alpha
Demonstrations Project
MathWorld
Integrator
Wolfram Functions Site
Mathematica Journal
Wolfram Media
Wolfram
Tones
Wolfram Science
Stephen Wolfram
DOCUMENTATION CENTER SEARCH
New to
Mathematica
?
Find your learning path
»
Mathematica
>
Core Language
>
List Manipulation
>
Rearranging & Restructuring Lists
>
Union (
)
>
Mathematica
>
Data Manipulation
>
Handling Arrays of Data
>
Rearranging & Restructuring Lists
>
Union (
)
>
Mathematica
>
Data Manipulation
>
Image Processing & Analysis
>
Basic Image Manipulation
>
Handling Arrays of Data
>
Rearranging & Restructuring Lists
>
Union (
)
>
BUILT-IN MATHEMATICA SYMBOL
Combining Lists
Lists as Sets
Tutorials »
|
Join
Intersection
Complement
Tally
DeleteDuplicates
BinLists
Split
Or
BitOr
See Also »
|
Discrete & Integer Data
Discrete Mathematics
Handling Arrays of Data
Math & Counting Operations on Lists
Numerical Data
Rearranging & Restructuring Lists
More About »
Union
Union
gives a sorted list of all the distinct elements that appear in any of the
.
Union
[
list
]
gives a sorted version of a list, in which all duplicated elements have been dropped.
MORE INFORMATION
If the
are considered as sets,
Union
gives their union.
Union
can be input in
StandardForm
and
InputForm
as
. The character
can be entered as
Esc
un
Esc
or
\[Union]
.
The
must have the same head, but it need not be
List
.
Union
[
list
1
,
...
,
SameTest
->
test
]
applies
test
to each pair of elements in the
to determine whether they should be considered the same.
EXAMPLES
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
Esc
un
Esc
:
Give a sorted list of distinct elements:
In[1]:=
Out[1]=
Give a sorted list of distinct elements from all the lists:
In[1]:=
Out[1]=
Enter using
Esc
un
Esc
:
In[1]:=
Out[1]=
Scope
(1)
Give a list of the distinct lists:
Generalizations & Extensions
(1)
Union
works with any head, not just
List
:
Options
(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
(2)
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
:
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
Tally
DeleteDuplicates
BinLists
Split
Or
BitOr
TUTORIALS
Combining Lists
Lists as Sets
MORE ABOUT
Discrete & Integer Data
Discrete Mathematics
Handling Arrays of Data
Math & Counting Operations on Lists
Numerical Data
Rearranging & Restructuring Lists
RELATED LINKS
NKS|Online
(
A New Kind of Science
)
New in 1 | Last modified in 3