Count the Number of Exact Lines
We will learn how to count the number of lines in a file by ignoring the empty lines.
We'll cover the following...
Removing empty lines
Here, we’ll learn how to write a piece of code that will remove all the empty lines.
We’ve written a piece of code that contains a for
loop. This will remove all the lines that are empty.
for l in lines:
if not l:
lines.remove(l)
Let’s go over this line by line.
...