匿名用户
我希望这能有所帮助:In [162]: q
Out[162]:
deque(['[5.0, 10.0]',
'[7.5, 9.0]',
'[8.8, 8.48]',
'[11.261467889908257, 9.956880733944955]',
'[11.5, 9.45]',
'[14.4, 8.0]',
'[15.47191011235955, 10.382022471910112]',
'[17.0, 10.0]'])
In [163]: [[float(x) for x in x.replace('\'','').replace('[','').replace(']','').split(',')] for x in q]
Out[163]:
[[5.0, 10.0],
[7.5, 9.0],
[8.8, 8.48],
[11.261467889908257, 9.956880733944955],
[11.5, 9.45],
[14.4, 8.0],
[15.47191011235955, 10.382022471910112],
[17.0, 10.0]]
另一个更短更好的方法:In [168]: q
Out[168]:
deque(['[5.0, 10.0]',
'[7.5, 9.0]',
'[8.8, 8.48]',
'[11.261467889908257, 9.956880733944955]',
'[11.5, 9.45]',
'[14.4, 8.0]',
'[15.47191011235955, 10.382022471910112]',
'[17.0, 10.0]'])
In [169]: [ast.literal_eval(x) for x in q]
Out[169]:
[[5.0, 10.0],
[7.5, 9.0],
[8.8, 8.48],
[11.261467889908257, 9.956880733944955],
[11.5, 9.45],
[14.4, 8.0],
[15.47191011235955, 10.382022471910112],
[17.0, 10.0]]