groups

groups(many_to_one)[source]

Converts a many-to-one mapping into a one-to-many mapping.

many_to_one must be a dictionary whose keys and values are all hashable.

The return value is a dictionary mapping values from many_to_one to sets of keys from many_to_one that have that value.

Examples

>>> from networkx.utils import groups
>>> many_to_one = {"a": 1, "b": 1, "c": 2, "d": 3, "e": 3}
>>> groups(many_to_one)  
{1: {'a', 'b'}, 2: {'c'}, 3: {'e', 'd'}}