Unique

Unique

Unique[ list ] returns a copy of a list without duplicates.

Usages

Unique[ list ]

Unique[ list ] returns a new list in which every element of list occurs only once. The elements keep the order of their first occurrence.

Example in out
Remove duplicates. Unique[ {1, x, 5, x, 1} ] {1, x, 5}
The first occurrence determines the order. Unique[ {3, 1, 3, 2, 1} ] {3, 1, 2}
Details
  • Equal elements: elements are equal if they are the same expression, regardless of the order of terms or factors: Unique[ {x+1, 1+x, 2} ] gives {x+1, 2}. Numbers must have the same form: Unique[ {2.4, 12/5} ] keeps both.
  • Empty list: Unique[ {} ] returns {}.
Invalid input Result
Unique[ 5 ] Error: the argument should be a list
Unique[ {1,2}, {3} ] Error: number of arguments should be 1

See also: Tally, Difference, RemoveAllFromList