我有一个字符串列表,如下所示:
['(0.027725, 0.0088202301), (0.00055000000000000003, 0.0040760101),
(0.1666, 0.0020067799), (0.00545, 0.021263899)']
但我希望它是一个看起来像这样的元组列表:
[(0.027725, 0.0088202301),
(0.00055000000000000003, 0.0040760101),
(0.1666, 0.0020067799),
(0.00545, 0.021263899)]
有谁知道怎么做?
答案 0 :(得分:0)
您可以使用ast.literal_eval
:
import ast
s = ['(0.027725, 0.0088202301), (0.00055000000000000003, 0.0040760101), (0.1666, 0.0020067799), (0.00545, 0.021263899)']
new_s = ast.literal_eval('[{}]'.format(s[0]))
输出:
[(0.027725, 0.0088202301), (0.00055, 0.0040760101), (0.1666, 0.0020067799), (0.00545, 0.021263899)]