title: generating 3 numbers whose sum is n
body: <p>I need to generate three natural numbers whose sum is <code>n</code>. The first number can be at max <code>x</code>, the second number can be at max <code>y</code> and the final number can be at max <code>z</code>. Currently I am doing this</p>
  
  <pre><code>def f(n):
      return [(i, j, k)
              for i in range(x+1)
              for j in range(y+1)
              for k in range(z+1)
              if i + j + k == n]
  </code></pre>
  
  <p>But <code>n</code> is very large, around <code>500</code> and <code>x, y, z</code> are less than 200.  Currently I have 3 variables <code>(i, j, k)</code> generated from 3 ranges. Can this be done using two loops inside list comprehension?</p>