[英]Converting string with int and dictionary to list
我有一个字符串str = '[1,"a",3,{1:2 , 4:5}]'
我必须将str
转换为列表,使得L = [1,"a",3,{1:2 , 4:5}]
在 python 中。
Use the built in eval()
function as so:使用内置的
eval()
函数,如下所示:
str = '[1,"a",3,{1:2 , 4:5}]'
new = eval(str)
print(new) # returns [1, 'a', 3, {1: 2, 4: 5}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.