Intermediate
Write a file and count its lines
Write save_lines(path, lines) that writes each string in the list lines to the file at path, one per line (each line ends with "\n"), in UTF-8.
Write count_nonempty(path) that returns how many lines in the file are not empty after stripping spaces. A line with only spaces does not count. Loop over the file line by line instead of using read().
What Check tests
save_linescreates the file with the linescount_nonemptycounts 2 for two lines- Blank lines are not counted
- Non-English text survives
- An empty list gives an empty file and a count of 0
- Saving again replaces the old content
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.