Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Non Empty Lines by Guest_5a80b5eb
import re
class line_counter:
'''
This is a pointless class, but trying to use 'with'
for something other than managing external resources
since CheckiO missions don't seem to use external data.
Has anyone found a use for 'with' in CheckiO?
'''
def __init__(self, text):
self.text = text
def __enter__(self):
return self
def __exit__(self, *exc):
return
def count(self):
return len([line for line in self.text.splitlines() if not re.fullmatch(' *', line)])
def non_empty_lines(text: str) -> int:
with line_counter(text) as lines:
return lines.count()
April 2, 2022
Comments: