📜  如何在 python 代码示例中从字符串中恢复列表

📅  最后修改于: 2022-03-11 14:45:46.219000             🧑  作者: Mango

代码示例1
# if you have list in string format and you want to convert it back into list type
# then you can use eval() function, for eg:
 
str_lst = "[code, in, python]"
lst = eval(str_lst)

output: [code, in, python]

# if you will try to use list() function, it won't help. 
# It will separate all element and make it all string
list(str_list)

output:
['[', 'c', 'o', 'd', 'e', ',', ' ', 'i', 'n', ',', ' ', 'p', 'y', 't', 'h', 'o', 'n', ']']