把"ABC"
转成 list 格式只要list("ABC")
就会得到["A", "B", "C"]
但如果需要把string格式的list转换成list呢?
如把
x = u'[ "A","B","C" , " D"]'
转成
x = ["A", "B", "C", "D"]
用 ast
库
>>> import ast
>>> x = u'[ "A","B","C" , " D"]'
>>> x = ast.literal_eval(x)
>>> x
['A', 'B', 'C', ' D']
>>> x = [n.strip() for n in x]
>>> x
['A', 'B', 'C', 'D']
网友评论