Algosim documentation: unique

unique

Removes duplicates from a container.

Syntax

Description

If L is a list or some other linear container, then unique(L) returns L with all duplicates removed; only the first occurrence of each value remains.

unique(L, ε) has the same behaviour, except that floating-point comparisons are made with epsilon ε.

RemoveDuplicates is a synonym for unique.

Examples

v ≔ ❨2, 1, 1, 2, 1, 3, 4, 1, 1, 2, 3, 4, 5, 1, 5, 1, 2, 3, 4, 1❩;
unique(v)
 ⎛2⎞
 ⎜1⎟
e⎜3⎟
 ⎜4⎟
 ⎝5⎠
unique(v, 1.5)
 ⎛2⎞
e⎝4⎠
Alice ≔ ExampleData("Alice in Wonderland") \ 50
ALICE’S ADVENTURES IN WONDERLAND

Lewis Carroll
…
#unique(words(Alice) @ UpperCase)
2778
#unique(characters(Alice))
74

See also