finesse.script.util.duplicates

finesse.script.util.duplicates(items, key=None)[source]

Get duplicate keys and values in the 1D sequence items.

Parameters
itemssequence

The sequence to find duplicates in.

keycallable, optional

The key function to use for comparisons. If not specified, defaults to the identity function.

Returns
list

The duplicates in items. This is a sequence of tuples containing the result of the key function for each entry of items, where at least two such keys exist, and the original items that matched that key.

Examples

>>> [k for k, _ in duplicates("AAAABBCDAAB")]
["A", "B", "C", "D"]
>>> [list(g) for _, g in duplicates("AAAABBCDAAB")]
[["A", "A", "A", "A", "A", "A"], ["B", "B", "B"], ["C"], ["D"]]