A file with the ad comments filtered out

Write code · Medium · §5.6, §9.3, §9.5 Where is it, and how is it written?

comments.txt in the data folder holds comments, one per line. Leave out blank lines and comments in which the text "ad" appears anywhere, and write the remaining comments to clean.txt in the data folder, one per line. End every line with a newline, and if clean.txt already exists, erase its old content and write it again from the start.

After writing, print the number of comments kept, like Comments kept: 2. Add encoding="utf-8" to every open().

Starter code

kept = 0
# Write your code here

print("Comments kept:", kept)

File data/comments.txt

Love it
Click this ad
Best café ever
Free ad event

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.