unique#
- unique(sequence: list)[source]#
Keep only unique values from a list (any Iterable should work).
Preserves the order of the sequence (except for sets of course).
- Parameters:
sequence (list) – List from which to keep only the unique values
- Returns:
List containing only unique values
- Return type:
Examples
>>> # With a list >>> unique([5, 4, 1, 2, 3, 1, 2]) [5, 4, 1, 2, 3]
>>> # With an array >>> unique(np.array([5, 4, 1, 2, 3, 1, 2])) [5, 4, 1, 2, 3]
>>> # With a set (sorts the values, as a set would do!) >>> unique({5, 4, 1, 2, 3, 1, 2}) [1, 2, 3, 4, 5]