Put a variable in a specific array position Python
<p>I am trying to solve a problem and I am not able to do it. So the problem is that I have a function in Python. And I have 3 cases and I want my function to be general for all these cases. So my function needs an argument which is a array like this <code>a = [a1, a2, a3]</code> and for each case 2 of the elements in the array are constant and the other is variable, I explain this in more detail with this example code:</p>

<pre><code># I have my function:

def example(r,a):
    # r is an array. Inside this function I have a for loop
    for i in xrange(len(r)):
         #inside this loop is where I have the 3 cases:
         a = [r[z], a[1], a[2]]
         a = [a[0], r[z], a[2]]    
         a = [a[0], a[1], r[z]]
    (rest of the code)
     ...
</code></pre>

<p>so I want to find a way to declare <code>a</code> so my function knows where to place the variable <code>r[z]</code> I know that it is posible to do it with if statments but I am looking for a one-line solution, something like a way to put the variable r[z] in a given position of the array a. Or I don't know any efficient way is appreciated.</p>

<p>Thank you in advance.</p>

<p>Regards</p>