Don't use any()
here; you don't even use the return value.
To write all matching terms, use:
terms_file.write(''.join(term for term in self.terms if term in line))
but it'd be better to just use a regular loop; readability counts!
for term in self.terms:
if term in line:
terms_file.write(term)
Use any()
only if you want to know about the boolean result of the test; any()
stops iterating when it finds the first True
value. In your case terms_file.write()
returns None
, so it'll never even encounter True
and always return False
.