"""The assignment's measurement, in one place (shared by training and evaluation).""" import regex # one faithful unit = a run of letters/marks/numbers, or one visible non-space symbol UNIT = regex.compile(r"[\p{L}\p{M}\p{N}]+|[^\s\p{L}\p{M}\p{N}]") def units(text): return len(UNIT.findall(text)) def visible(text): return "".join(text.split())