openmnglab.util.dicts.group_dict#

openmnglab.util.dicts.group_dict(vals: Iterable[_VT_co], key_getter: Callable[[_VT_co], _KT]) dict[~_KT, list[+_VT_co]][source]#

groups the given vals in a dictionary by the key returned from the key getter. More robust as the groupby variant of itertools, as it doesn’t require the data to be sorted first. :param vals: values to be grouped :param key_getter: function that produces the key the given value should be grouped by :return: a dictionary containing the grouped values