normalize(text) replacing every run of whitespace (spaces, tabs, newlines) with a single space and trimming the ends — re.sub(r'\s+', ' ', ...) then strip().normalize(' hello\t\tworld \n twice ')'hello world twice'
All whitespace runs collapse to single spaces.
\s matches all whitespace classes.
Chain .strip() after the sub.