def group_by_key_func(func):
    """
    Create a dictionary from an iterable such that the keys are the result of evaluating a key function on elements
    of the iterable and the values are lists of elements all of which correspond to the key.
    """
    assertEqual(func("a bb ccc d ee fff".split(), len),
                {1: ["a", "d"],
                 2: ["bb", "ee"],
                 3: ["ccc", "fff"]})

    assertEqual(func([-1, 0, 1, 3, 6, 8, 9, 2], lambda x: x % 2),
                {0: [0, 6, 8, 2],
                 1: [-1, 1, 3, 9]})
dataset/ETHPy150Open alexmojaki/funcfinder/funcfinder/questions/dict.py/group_by_key_func/original