listlib::removeDuplicates -- removes
duplicate entries
Introductionlistlib::removeDuplicates(list) removes
all duplicate entries of the list list.
Call(s)listlib::removeDuplicates(list)
listlib::removeDuplicates(list, KeepOrder)
Parameterslist |
- | a MuPAD list |
OptionsKeepOrder |
- | listlib::removeDuplicates(list, KeepOrder) returns a list with unique entries
in the order of their occurence in list. |
Returnsa list that contains each entry only once
Related
Functionslistlib::removeDupSorted,
DOM_LIST
Detailslistlib::removeDuplicates(list) removes
all duplicates of each entry of the list list. The new
list is build up from right to left with the order of the last
occurence of each entry in list. Cf. Example 1.set and back into a
list. You will loose the order of the list entries in this case. Cf.
Example 3.
Option: KeepOrderlistlib::removeDuplicates(list, KeepOrder) returns a list of the entries of
list in the order of their first occurence. The
list is build up from left to right. Cf. Example 2.
Example
1Per default listlib::removeDuplicates
removes duplicate entries in reverse order:
>> list:= [1, 1, 1, 3, 1, 5, 5, 1, 3, 3, 1, 7]: listlib::removeDuplicates(list)
[5, 3, 1, 7]
Example
2With option KeepOrder entries are selected in the order of their occurence:
>> list:= [1, 1, 1, 3, 1, 5, 5, 1, 3, 3, 1, 7]: listlib::removeDuplicates(list, KeepOrder)
[1, 3, 5, 7]
Example
3If you don't need the order of list entries any more, you may convert the list into a set and back into a list:
>> list:= [1, 1, 1, 3, 1, 5, 5, 1, 3, 3, 1, 7]:
[op({op(list)})]
[7, 5, 3, 1]
listtools::removeDuplicates