import itertools


def groupby(iterable, keyfunc):
    """
    Group iterable by keyfunc
    :param iterable: iterable obj
    :param keyfunc: group by keyfunc
    :return: dict {<keyfunc result>: [item1, item2]}
    """
    data = sorted(iterable, key=keyfunc)
    return {
        k: list(g)
        for k, g in itertools.groupby(data, keyfunc)
    }