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 a = [a1, a2, a3]
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:
# 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)
...
so I want to find a way to declare a
so my function knows where to place the variable r[z]
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.
Thank you in advance.
Regards