class iteration_utilities.unique_everseen(iterable, key=None)

Find unique elements, preserving their order. Remembers all elements ever seen.

iterable : iterable

Iterable containing the elements.

key : callable, optional

If given it must be a callable taking one argument and this callable is applied to the value before checking if it was seen yet.

iterable : generator

An iterable containing all unique values ever seen in the iterable.


The items in the iterable should implement equality.

If the items are hashable the function is much faster.


Some simple examples:

>>> from iteration_utilities import unique_everseen
>>> list(unique_everseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D']

>>> list(unique_everseen('ABBCcAD', str.lower))
['A', 'B', 'C', 'D']

Even unhashable values can be processed, like list:

>>> list(unique_everseen([[1, 2], [1, 1], [1, 2]]))
[[1, 2], [1, 1]]

However using key=tuple (to make them hashable) will be faster:

>>> list(unique_everseen([[1, 2], [1, 1], [1, 2]], key=tuple))
[[1, 2], [1, 1]]

One can access the already seen values by accessing the seen attribute.


(callable or None) The key function (readonly).


(Seen) Already seen values (readonly).