def group_by(fun, arr):
    """Group items by value
    >>> arr = [{'item': '1', 'v': 2},{'item': '2', 'v': 3},{'item': '1', 'v': 3}]
    >>> list(sorted(map(lambda x: len(x['items']), group_by(lambda x: x['item'], arr))))
    [1, 2]
    """
    ret = {}
    for item in arr:
        val = fun(item)
        if val in ret:
            ret[val].append(item)
        else:
            ret[val] = [item]
    for k, v in ret.items():
        yield {'key': k, 'items': v}
