import itertools


def groups(outcomes, g = True):
    """Generates a list of groups of outcomes.

    Example: [ "H", "H", "T", "T", "H", "H", "H", "H", "T", "T" ]

    ["H", 2]
    ["T", 2]
    ["H", 4]
    ["T", 2]

    Parameters:
        outcomes = iterable of outcomes
        g = True for generator
    """
    if g:
        for val, streak in itertools.groupby(outcomes):
            yield [val, sum([1 for _ in streak])]
    else:
        return [[val, sum([1 for _ in streak])] for val, streak in itertools.groupby(outcomes)]