I have a function f(x)
in which many local variables are created. x
is a string with the same name as one of these local variables and I would like to change this local variable by changing x
. What is the clean way to do this? Currently I am using a lot of if/elif
statements.
Some dummy code to represent my problem:
def f(x):
a = [1,2,3]
b = [2,3,4]
c = [3,4,5]
if x == "a":
a[0] = 10
elif x == "b":
b[0] = 10
elif x == "c":
c[0] = 10
return a,b,c
I would like for the right variable to change value but using all these if/elif statements feels a bit redundant.