baybe.utils.basic.group_duplicate_values

baybe.utils.basic.group_duplicate_values(dictionary: dict[_T, _U])[source]

Identify groups of keys that have the same value.

Parameters:

dictionary (dict[TypeVar(_T), TypeVar(_U)]) – The dictionary to screen for duplicate values.

Return type:

dict[TypeVar(_U), list[TypeVar(_T)]]

Returns:

A dictionary whose keys are a subset of values of the input dictionary, and whose values are lists that group original keys holding the same value.

Example

>>> group_duplicate_values({"A": 1, "B": 2, "C": 1, "D": 3})
{1: ['B', 'C']}