lisa.utils.group_by_value#

lisa.utils.group_by_value(mapping, key_sort=<function <lambda>>)[source]#

Group a mapping by its values

Parameters:
Return type:

collections.OrderedDict

The idea behind this method is to “reverse” a mapping, IOW to create a new mapping that has the passed mapping’s values as keys. Since different keys can point to the same value, the new values will be lists of old keys.

Example:

>>> group_by_value({0: 42, 1: 43, 2: 42})
OrderedDict([(42, [0, 2]), (43, [1])])