我有一个文件(test.txt的)和内容如下:找到某些字在文件中的python
I0914 17:37:15.763941 29832 abc.cpp:138] Iteration 0, Testing (#0)
I0922 16:14:14.933842 2057 abc.cpp:176] Test score #0: 0.146329
I0914 17:37:15.763941 29832 abc.cpp:138] Iteration 1000, Testing (#0)
I0922 16:14:14.933842 2057 abc.cpp:176] Test score #0: 0.246222
I0914 17:37:15.763941 29832 abc.cpp:138] Iteration 2000, Testing (#0)
I0922 16:14:14.933842 2057 abc.cpp:176] Test score #0: 0.335429
I0914 17:37:15.763941 29832 abc.cpp:138] Iteration 3000, Testing (#0)
I0922 16:14:14.933842 2057 abc.cpp:176] Test score #0: 0.445429
I0914 17:37:15.763941 29832 abc.cpp:138] Iteration 4000, Testing (#0)
I0922 16:14:14.933842 2057 abc.cpp:176] Test score #0: 0.546429
,我的问题是,如何让迭代(0,1000,2000年的数量.. 。,4000)和考试分数(0.146329,0.246222,0.335429 .... 0.546429)并将它们组合成字典。
例如,我的预期结果如下:提前
dict = {'0':0.146329,
'1000':0.246222
'2000':0.335429
'3000':0.445429
'4000':0.546429}
感谢。
@Fledgling我已经读文件到“行”,并找到关键字(迭代和分数),像得分= [线线线线,如果“分数”],ITER = [如果行中有“迭代”行,则将行分隔),然后我不知道要解决问题... – RyanLiu 2014-09-23 03:01:04