How can I continuously replace an element of an array?
<p>At each time step, I am trying to replace one element of my <code>list</code> with the sum of the other 2 plus 1. This is my code:</p>

<pre><code>def replace(x, y, z):

    for i in range(3):

        rep_x = [y+z+1, y, z]
        rep_y = [x, x+z+1, z]
        rep_z = [x, y, x+y+1]

        ini_x = rep_x
        ini_y = rep_y
        ini_z = rep_z

    return ini_x, ini_y, ini_z


print replace(2, 4, 6)
</code></pre>

<p>This gives me a single line - a one-time replacement. I would like the code to keep doing the replacements on the newly-obtained arrays every time, for example:</p>

<p>([11, 4, 6], [2, 9, 6], [2, 4, 7])
((11, 4, 6], [11, 18, 6], [11, 4, 16]), ([19, 9, 6], [2, 9, 6], [2, 9, 12]), ([12, 4, 7], [2, 10, 7], [2, 4, 7]))</p>

<p>How can I do this?</p>

<blockquote>
  <p>at each time step, replace one element of my array with the sum of the other 2 plus 1</p>
</blockquote>

<pre><code>from __future__ import print_function
def business(array): # Can't give a proper name without knowing what the function does
    total = sum(array)
    return [total + 1 - x for x in array]

arr = [2,4,6]
steps = 10
print(arr)
for step in range(steps):
    arr = business(arr)
    print(arr)
</code></pre>

python arrays python-2.7