File size: 583 Bytes
1600cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | """Counting words and lines in plain text notes.
The module is deliberately untyped at the edges: some of its parameters carry a
literal default and no annotation, which is the shape the annotation pattern of this
bundle is allowed to touch.
"""
def count_words(text="", unit="word"):
parts = text.split()
if unit == "word":
return len(parts)
if unit == "line":
return len(text.splitlines())
return 0
def count_lines(text: str = "") -> int:
return len(text.splitlines())
def summarize(text, unit="word"):
return count_words(text, unit)
|