(n)
Similar to revlex_partitions, but in lexicographic order.
Similar to revlex_partitions, but in lexicographic order.
Similar to revlex_partitions but in lexicographic order .
def lex_partitions(n):
    """Similar to revlex_partitions, but in lexicographic order."""
    if n == 0:
        yield []
    if n <= 0:
        return
    for p in lex_partitions(n-1):
        p.append(1)
        yield p
        p.pop()
        if len(p) == 1 or (len(p) > 1 and p[-1] < p[-2]):
            p[-1] += 1
            yield p
            p[-1] -= 1
def lex_partitions ( n ) : if n == 0 : yield [ ] if n <= 0 : return for p in lex_partitions ( n - 1 ) : p . append ( 1 ) yield p p . pop ( ) if len ( p ) == 1 or ( len ( p ) > 1 and p [ - 1 ] < p [ - 2 ] ) : p [ - 1 ] += 1 yield p p [ - 1 ] -= 1