Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
This took me way too long ~_~ solution in Clear category for Non Empty Lines by jrchionis
def non_empty_lines(text: str) -> int:
non_empty_lines_counter = 0
itemized_text = text.split("\n")
for element in itemized_text:
stripped_element = element.strip()
if stripped_element != "":
non_empty_lines_counter += 1
return non_empty_lines_counter
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!")
July 21, 2024
Comments: