在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python  網(wǎng)絡(luò)安全/ 用python查找連續(xù)行

用python查找連續(xù)行

我有一個文檔,內(nèi)容類似于

the line 1 is:
a-b-o 
the line 2 is:
not found
the line 3 is:
not found
the line 4 is:
a-c-k
the line 5 is:
a-d-g
a-h-o
the line 6 is:
a-g-i
the line 7 is:
not found

這種。我想用python得到連續(xù)的有內(nèi)容的那幾行,而不是not found的那幾行。以上面的為例,我想得到的結(jié)果是:

the line 4 is:
a-c-k
the line 5 is:
a-d-g
a-h-o
the line 6 is:
a-g-i

請問大家可以怎么實現(xiàn),謝謝。
回答
編輯回答
懶豬

不知道你這文件大不大。如果不大,你可以一次讀出,記為txt,然后以"not found"分割txt,特殊判斷txt[0]txt[-1];對于剩下的txt[x],如果內(nèi)容中有大于2個"line"字符串,說明這就是符合要求的,做一做處理,然后輸出。
如果文件比較大,可以一部分一部分讀取,然后判斷連接位置的情況,其余的還是按上述處理

2018年7月25日 22:36