w2 = "космодром"
with open("base.txt") as bh:
lines = [line for line in bh]
with open("base.txt", "w") as bh, open("deleted.txt", "w") as dh:
handler = {True: dh, False: bh}
for line in lines:
handler[w2 in line].write(line)
w3 = None if dh.tell() else w2