Python list string to list

后端 未结 6 1448
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 11:51

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]]
         


        
6条回答
  •  既然无缘
    2021-01-21 12:46

    why not use eval()?

    >>> s = "[7, 9, 41, [32, 67]]"
    >>> eval(s)
    [7, 9, 41, [32, 67]]
    

提交回复
热议问题