Untitled
unknown
python
10 months ago
750 B
3
Indexable
Never
def rem_one(text, pat): new_text = [] for word in text.split(' '): new_w = [] for w in word.split('\n'): if re.match(pat, w.lower()): new_w += [re.sub(pat, '', w.lower())] else: new_w += [w] new_text += ['\n'.join(new_w)] return ' '.join(new_text) import re def remq(fstr1, fstr2, fstr3): with (open(fstr1, mode='r') as f1, open(fstr2, mode='r') as f2, open(fstr3, mode='w') as f3): text = f1.read() inappr = f2.read().split() new_text = text for i in inappr: new_text = rem_one(new_text, i) f3.write(new_text) remq('tmp1.txt', 'tmp.txt', 'output.txt')
Leave a Comment