def prefixes(seq):
    """
    Generate all prefixes of a sequence.

    Examples
    ========

    >>> list(prefixes([1, 2, 3, 4]))
    [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]]

    """
    n = len(seq)
    for i in range(n):
        yield seq[:i + 1]
