• + 7 comments

    It is in lexographical order due to the nature of the loops. Spaced out it looks somewhat like

    for a in range(x+1):
    
        for b in range(y+1):
    
            for c in range(z+1):
    
                if a + b + c != n:
                    print(stuff is here)
    

    We start at [0,0,0]. Then c will increment to get to [0,0,1] When c hits [0,0,z], we get [0,1,0] as the next in the loop. This pattern continues and gives us the lexographical ordering required of the output.