Python将字符串列表转换为列表 [英] Python Convert String List to List
本文介绍了Python将字符串列表转换为列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个格式如下的python列表:
So I have a list of python formatted like:
x = ['[1,2,3]', '[4,5,6,]', ...]
是否可以将内部列表"转换为实际列表?因此输出将为
Is there a way to convert the "inner lists" to actual lists? So the output would be
x = [[1,2,3], [4,5,6], ....]
谢谢!
推荐答案
另一个使用json
的示例:
>>> import json
>>> x = ['[1,2,3]', '[4,5,6]']
>>> [json.loads(y) for y in x]
[[1, 2, 3], [4, 5, 6]]
请仅将字符串限制为dict
和list
.
Please limit your strings to dict
s and list
s only.
这篇关于Python将字符串列表转换为列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文