我有一个稍微不同的问题比以前提出的问题有关此主题。文本文件有以下内容python文件到字典
x1 x2 x3 gh3 tf2
0.1 0.7 0.8 0.9 8.9
y1 ft gt hh
2 4 7 8
.
.
.
我想添加到字典,所以有键:值x1:0.1等等。
这是我现在有,它并没有真正为我工作
ned = {}
nel =[]
with open('test.dat', 'r') as f:
for line in f:
splitline= line.split()
print(splitline)
ned[int(splitline[0])] = ",".join(splitline[1:])
这是最蟒蛇回答不错,但也是不可读的。这取决于你我喜欢的东西;) –