(n)
Integer partitions of n, in reverse lexicographic order.
    Note that the generated output consists of the same list object,
    repeated the correct number of times; the caller must leave this
    list unchanged, and must make a copy of any partition that is
    intended to last longer than the next call into the generator.
    The algorithm follows Knuth v4 fasc3 p38 in rough outline.
Integer partitions of n, in reverse lexicographic order.
    Note that the generated output consists of the same list object,
    repeated the correct number of times; the caller must leave this
    list unchanged, and must make a copy of any partition that is
    intended to last longer than the next call into the generator.
    The algorithm follows Knuth v4 fasc3 p38 in rough outline.
Integer partitions of n in reverse lexicographic order . Note that the generated output consists of the same list object repeated the correct number of times ; the caller must leave this list unchanged and must make a copy of any partition that is intended to last longer than the next call into the generator . The algorithm follows Knuth v4 fasc3 p38 in rough outline .
def mckay(n):
    """
    Integer partitions of n, in reverse lexicographic order.
    Note that the generated output consists of the same list object,
    repeated the correct number of times; the caller must leave this
    list unchanged, and must make a copy of any partition that is
    intended to last longer than the next call into the generator.
    The algorithm follows Knuth v4 fasc3 p38 in rough outline.
    """
    if n == 0:
        yield []
    if n <= 0:
        return
    partition = [n]
    last_nonunit = (n > 1) - 1
    while True:
        yield partition
        if last_nonunit < 0:
            return
        if partition[last_nonunit] == 2:
            partition[last_nonunit] = 1
            partition.append(1)
            last_nonunit -= 1
            continue
        replacement = partition[last_nonunit] - 1
        total_replaced = replacement + len(partition) - last_nonunit
        reps,rest = divmod(total_replaced,replacement)
        partition[last_nonunit:] = reps*[replacement]
        if rest:
            partition.append(rest)
        last_nonunit = len(partition) - (partition[-1]==1) - 1
def mckay ( n ) : if n == 0 : yield [ ] if n <= 0 : return partition = [ n ] last_nonunit = ( n > 1 ) - 1 while True : yield partition if last_nonunit < 0 : return if partition [ last_nonunit ] == 2 : partition [ last_nonunit ] = 1 partition . append ( 1 ) last_nonunit -= 1 continue replacement = partition [ last_nonunit ] - 1 total_replaced = replacement + len ( partition ) - last_nonunit reps , rest = divmod ( total_replaced , replacement ) partition [ last_nonunit : ] = reps * [ replacement ] if rest : partition . append ( rest ) last_nonunit = len ( partition ) - ( partition [ - 1 ] == 1 ) - 1