Py学习  »  Rachit Bhargava  »  全部回复
回复总数  1
6 年前
回复了 Rachit Bhargava 创建的主题 » 基于python中两个短序列的过滤行

如果 mot1 在里面找到的有一种方法:

from math import ceil

infile = open('infile.txt', 'r')
text = infile.readlines()
infile.close()

mot1 = 'AATAAA'
mot2 = 'GGAC'

check = [(text[x], text[x+1]) for x in range(ceil(len(text)/2))]

result = [(x + '\n' + y) for (x, y) in check if mot1 in y and mot2 in y[(y.find(mot1)+len(mot1)+2):]]

with open('outfile.txt', "w") as f:
    for item in result:
        f.write("%s\n" % item)