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
dict
Simply, use a dict:
def f(x):
values = {
"a": [1,2,3],
"b": [2,3,4],
"c": [3,4,5]
}
values[x][0] = 10
return values["a"], values["b"], values["c"]
If you really really want, use your original code and do locals()[x][0] = 10
but that's not really recommended because you could cause unwanted issues if the argument is the name of some other variable you don't want changed.