def gen(n): # tuple version if n == 0: yield () return for p in gen(n-1): yield (1, ) + p if p and (len(p)<2 or p[1] > p[0]): yield (p[0] + 1, ) + p[1:]

I'm mostly troubled with the statement "yield", and while I've googled for examples, none of them seem to be helping me understand this code as none of them use it in this way.