def groupby_count(i, key=None, force_keys=None):
counter = defaultdict(lambda: <NUM_LIT:0>)<EOL>if not key:<EOL><INDENT>key = lambda o: o<EOL><DEDENT>for k in i:<EOL><INDENT>counter[key(k)] += <NUM_LIT:1><EOL><DEDENT>if force_keys:<EOL><INDENT>for k in force_keys:<EOL><INDENT>counter[k] += <NUM_LIT:0><EOL><DEDENT><DEDENT>return counter.items()<EOL>
Aggregate iterator values into buckets based on how frequently the
    values appear.

    Example::

        >>> list(groupby_count([1, 1, 1, 2, 3]))
        [(1, 3), (2, 1), (3, 1)]