I’m considering you have a string answer stored in the variable c
and you want to access a list with the respective name. With this objective, you can use the python function eval()
.
From the python docs (here) you have that:
eval(expression[, globals[, locals]])
The expression argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the globals and locals
dictionaries as global and local namespace.
It means that in your case, eval will get your string check if your python namespace has have variables with this name. The result is the following:
c="L1"
print (eval(c)) # it will print the list L1 = [1,2,3,4]
The code above will get you where you want. Although I have never used in any real use case I had to work with.
Obs: Thanks for rewriting the question! 🙂
3
solved Change the type between str and the name of list