我有一个分数列表,例如:

data = ['24/221 ', '25/221 ', '24/221 ', '25/221 ', '25/221 ', '30/221 ', '31/221 ', '31/221 ', '31/221 ', '31/221 ', '30/221 ', '30/221 ', '33/221 ']

我将如何将其转换为浮点数,例如
data = ['0.10 ', '0.11 ', '0.10 ', '0.11 ', '0.13 ', '0.14 ', '0.14 ', '0.14 ', '0.14 ', '0.14 ', '0.13 ', '0.13 ', '0.15 ']
Fraction模块似乎只能转换为Fractions(不是从),而float([x])需要字符串或整数。

最佳答案

import fractions
data = [float(fractions.Fraction(x)) for x in data]

或与您的示例完全匹配(数据以字符串结尾):
import fractions
data = [str(float(fractions.Fraction(x))) for x in data]

10-08 20:02