用一个文档中的一行中的一部分作为搜索条件,在另一个文档中找到有这个条件的一行,并且复制这一行除了搜索条件的其他部分
思路,首先选择好搜索关键词,然后用readlines读取另一个文档内容,保存为行列表形式,遍历查找即可。示例:
s='''this is a test
he is a student
a middle school student in class one'''
kw='student'
for a in s.split('\n'):
if kw in a:
print(' '.join(a.split(kw)))
用正则匹配