0
我有一个带有994行和7列的.txt文件。第二栏列出了与第三栏残留物相互作用的蛋白质残基的名称。其余的右边是分数(前两个不重要)。文件中的字典只显示最后一行
我想把它变成一个字典,第二列的元素作为关键字,其余作为关键值。问题是它似乎只是放在最后一行。
这是我的代码:
>>> f=open('C:/Users/Alex/Documents/1TRKGremlin.txt')
>>> dict={}
>>> for line in f:
... lsplit=line.split()
>>> try:dict[lsplit[2]].appendl(lsplit[3:])
... except KeyError: dict[lsplit[2]]=[lsplit[3:]]
>>>print dict[]#here I only get the last line of the file
文件看起来是这样的:
i j i_id j_id r_sco s_sco prob
205 208 205_K 208_E 0.5625 3.889 1.000
557 660 557_I 660_A 0.5471 3.783 1.000
425 439 425_M 439_G 0.5462 3.776 1.000
19 76 19_A 76_S 0.4867 3.365 1.000
436 462 436_K 462_P 0.4770 3.298 1.000
579 661 579_K 661_Q 0.4446 3.074 1.000
谢谢!
感谢您的建议,它现在可以工作。 – Alexandra