title: for loop misery
body: <p>I'm trying to loop through an array, compute some values and store them in another array (<code>output</code>). However, what I tried (see bellow) always prints the last value in the <code>inarray</code> and the last computed <code>sum</code> (not the max value, as intended) and the <code>output</code> array also only contains the last value. I figured the <code>output.append(sum)</code> should append the <code>sum</code> value each time throughout the loop, but it doesn't. If I print the sum values directly though, it shows on the console. What am I doing wrong?</p>
  
  <pre><code>def discountCombinations(inarray):
      for i in range(len(inarray)):
          max = 0
          maxi = 0
          output = list()
          ...
          #do stuff
          ...
          sum = new_y.sum()
          output.append(sum)
          print sum
          if sum &gt; max:
              max = copy.copy(sum)
              maxi = copy.copy(i)
      print (max,": ", inarray[maxi])
      print output
  </code></pre>