我有一个文件“test.txt”。其数据采用以下样式:
[(5.0, 1.12, 1, ((False, []), 0.85)), (4.21, 3.2, 2, ((True, []), 0.7997))]\n
本例仅显示文件中的第一行,该文件实际上有20行
在每一行中,它以“[”开始,以“]”结束(请注意“\n”只是一个新行符号)。 如您所见,每行中的模式是“[(()),((()),…]”。在实际情况中,一个“[]”内有10000个“(())”
你知道如何使用python3阅读这些信息吗
我想要的结果是
x_row1 = [[5.0, 1.12, 1],
[4.21, 3.2, 2],
...,
] # len(x_row1) == 10000
y_row1 = [[False, []], 0.85],
[True, []], 0.7997],
...,
] # len(y_row1) == 10000
x_row_all = [[x_row1], [x_row2], ..., [x_row20]]
y_row_all = [[y_row1], [y_row2], ..., [y_row20]]
谢谢
使用^{} :
针对您的具体问题:
如果确实需要元组成为列表,请改为:
或者,如果将
all_rows
创建为:相关问题 更多 >
编程相关推荐