I have a string:
s= \"[7, 9, 41, [32, 67]]\"
and I need to convert that string into a list:
l= [7, 9, 41, [32, 67]]
Use the ast module, it has a handy .literal_eval() function:
ast
import ast l = ast.literal_eval(s)
On the python prompt:
>>> import ast >>> s= "[7, 9, 41, [32, 67]]" >>> ast.literal_eval(s) [7, 9, 41, [32, 67]]