title: Set list elements to 0 from an index to the end if partial sum is under certain value
body: <p>Having a list of numbers, say:</p>
  <pre><code>numbers = [4, 5, 7, 2]
  </code></pre>
  <p>How could I write a function f that takes the list and a value and returns these results (I think the examples explains better):</p>
  <pre><code>f(numbers, 4)
  [4, 0, 0, 0]
  
  f(numbers, 3)
  [0, 0, 0, 0]
  
  f(numbers, 10)
  [4, 5, 0, 0]
  
  f(numbers, 17)
  [4, 7, 7, 0]
  </code></pre>
  <p>I need to update the list with zeros from and index i such that sum(l[0:i]) &lt;= val and sum(l[0:i+1]) &gt; val.</p>
  <p>I tried:</p>
  <pre><code>def f(numbers, val, last_index=-1):
      if sum(numbers[0:last_index]) &gt; val:
           numbers[last_index] = 0
           last_index -= 1
           f(numbers, val, last_index)
  </code></pre>
  <p>I need to mutate the objects contained in the list. Not allowed to make copies. The function I've written does not work.</p>