Partitions of an integer and filtering by number of elements
First a technical note.  In mathematics, 2+3 is the same partition as 3+2.  The right name for what you are looking for are combinations.

That said, you are spending most of your time coming up with answers that you will throw away.  Don't.  Spend it coming up with answers that you won't throw away.  Like this:

def compositions(n, size):
    if n == 0 and size == 0:
        yield []
    elif 0 &lt; size:
        for i in range(1, n-size+2):
            for c in compositions(n-i, size-1):
                yield c + [i]

for c in compositions(25, 2):
    print(c)


Update

Since you actually do want partitions, here is an equivalent approach for partitions.

def partitions(n, size, limit=None):
    if limit is None:
        limit = n
    if n == 0 and size == 0:
        yield []
    elif size * limit &lt; n:
        # No solutions possible.
        pass
    elif 0 &lt; size:
        for i in range(1, min(limit, n-size+1)+1):
            for c in partitions(n-i, size-1, i):
                yield [i] + [c]