您的列表当前包含一个维度,以逗号分隔的字符串表示您的价格。
只需使用.split(',')
将这些字符串转换为列表;列表理解使这变得轻而易举:
splitlist = [prices.split(',') for prices in yourlist]
这会产生一个列表列表:
[['0.0740', '0.0730', '0.0720', '0.0300', '0.0290', '0.0240', '0.0210', '0.0200'], ['0.0200', '0.0200', '0.0150'], ['0.0260', '0.0260', '0.0200', '0.0200', '0.0200', '0.0150'], ['0.0210', '0.0210', '0.0200', '0.0170'], ['0.0770', '0.0760', '0.0740', '0.0550', '0.0450', '0.0210'], ['0.0530', '0.0520', '0.0510', '0.0230', '0.0220'], ['0.0160', '0.0160']]
并且splitlist[0][0]
是字符串'0.0740'
。
如果您需要以浮点值而不是字符串结束,只需map()
在拆分字符串上应用:
splitlist = [map(float, prices.split(',')) for prices in yourlist]
以便将每个单独的价格映射到float()
调用。现在你有:
[[0.073999999999999996, 0.072999999999999995, 0.071999999999999995, 0.029999999999999999, 0.029000000000000001, 0.024, 0.021000000000000001, 0.02], [0.02, 0.02, 0.014999999999999999], [0.025999999999999999, 0.025999999999999999, 0.02, 0.02, 0.02, 0.014999999999999999], [0.021000000000000001, 0.021000000000000001, 0.02, 0.017000000000000001], [0.076999999999999999, 0.075999999999999998, 0.073999999999999996, 0.055, 0.044999999999999998, 0.021000000000000001], [0.052999999999999999, 0.051999999999999998, 0.050999999999999997, 0.023, 0.021999999999999999], [0.016, 0.016]]
并splitlist[0][0]
具有浮点值0.073999999999999996
。