## `listlib::removeDuplicates` -- removes duplicate entries

#### Introduction

`listlib::removeDuplicates(`list`)` removes all duplicate entries of the list `list`.

#### Call(s)

`listlib::removeDuplicates(list)`
`listlib::removeDuplicates(list, KeepOrder)`

#### Parameters

`list` | - | a MuPAD list

#### Options

`KeepOrder` | - | `listlib::removeDuplicates(`list, KeepOrder`)` returns a list with unique entries in the order of their occurence in `list`.

#### Returns

a list that contains each entry only once

#### Related Functions

`listlib::removeDupSorted`, `DOM_LIST`

#### Details

- `listlib::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.
- A faster possibibliy to remove duplicate entries is to convert the list into a `set` and back into a list. You will loose the order of the list entries in this case. Cf. Example 3.

#### Option: KeepOrder

- `listlib::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 1

Per 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 2

With 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 3

If 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]

#### Changes

- used to be called `listtools::removeDuplicates`

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000