Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_lines(lst):
- """ (list of str) -> int
- Precondition: each str in lst[:-1] ends in \n.
- Return the number of non-blank, non-empty strings in lst.
- >>> count_lines(['The first line leads off,\n', '\n', ' \n',
- ... With a gap before the next.\n', 'Then the poem ends.\n'])
- 3
- """
- total_lines = 0
- blank_lines = 0
- nonblank_lines = 0
- #goes through each element of the list
- for line in lst:
- total_lines += 1
- if line.isalnum() or line.isspace():
- blank_lines += 1
- else:
- nonblank_lines += 1
- print(total_lines, blank_lines, nonblank_lines)
- return nonblank_lines
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement