Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Non Empty Lines by mennadiego
def non_empty_lines(text: str) -> int:
"""
You need to count how many non-empty lines a given text has.
An empty line is a line without symbols or the one that contains only spaces.
:param text: str - input text
:return: - int - count non empty lines
"""
# Get lines in input text
lines = [line.strip() for line in text.split('\n')]
# Get number of non empty lines
return len([line for line in lines if len(line) > 0])
print("Example:")
print(non_empty_lines("one simple line\n"))
# These "asserts" are used for self-checking
assert non_empty_lines("one simple line\n") == 1
assert non_empty_lines("") == 0
assert non_empty_lines("\nonly one line\n ") == 1
assert (
non_empty_lines(
"\nLorem ipsum dolor sit amet,\n\nconsectetur adipiscing elit\nNam odio nisi, aliquam\n "
)
== 3
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 29, 2023