Normalize whitespace

Write codeEasy12 min

Your task

Text pasted into a form arrives with messy whitespace. Normalize it: replace every run of spaces, tabs, and newlines with a single space, and remove leading and trailing whitespace entirely. All other characters are unchanged. For example, ' hello\t\tworld \n twice ' becomes 'hello world twice'.

Examples

normalize_spaces(text: str) -> str
Example 1
Inputnormalize_spaces(" hello\t\tworld \n twice ")
Output"hello world twice"