def groupBy(key, iterable):
    """
        groupBy(key: function, iter: iterable)
            iterable elements grouped by key function

        args:
            key = L x: x%2,   iter = [1,2,3]
        return:
            {0:[2], 1:[1,3]}
    """
    res = {}
    for x in iterable:
        k = key(x)
        if k not in res: res[k] = []
        res[k].append(x)
    return res