如何在Python中解析字符串列表?
myStringValue = "[['5', 1], ['1', 5], ['3', 3], ['3', 6], ['4', 5], ['4', 3], ['4', 5], ['6', 6], ['4', 1], ['3', 4]]"
如何将myStringValue
转换为列表?
答案 0 :(得分:1)
使用它时要小心,因为它可以被利用,但eval()
是前进的方向:
>>> myStringValue = "[['5', 1], ['1', 5], ['3', 3], ['3', 6], ['4', 5], ['4', 3], ['4', 5], ['6', 6], ['4', 1], ['3', 4]]"
>>> eval(myStringValue)
[['5', 1], ['1', 5], ['3', 3], ['3', 6], ['4', 5], ['4', 3], ['4', 5], ['6', 6], ['4', 1], ['3', 4]]
>>> type(eval(myStringValue))
<type 'list'>