def collatz(n):
    """
    Generates the Collatz sequence initiated by n.  Stops after 1 is yielded.
    Input: n -- an integer
    Output: Sequence of integers
    Examples:
    >>> list(collatz(11))
    [11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
    """
    yield n
    while n != 1:
        n = 3 * n + 1 if n % 2 else n // 2
        yield n
