easy +5 pts

Normalize Whitespace

Replace runs of whitespace with a single space and strip edges.

Write a function `normalize(s)` that takes a string `s` and returns a new string where every maximal sequence of whitespace characters (spaces, tabs, newlines, and other Unicode whitespace) is replaced by exactly one space, and leading/trailing whitespace is removed. For example, `normalize(" hello world\n")` should return `"hello world"`. If the input consists only of whitespace, return an empty string.

Constraints

Input is a string of length 0 to 100,000. Use Python's built-in string methods; no external libraries.

Example

>>> normalize("  hello   world\n")
'hello world'
>>> normalize("a\t\tb")
'a b'
>>> normalize("   ")
''
5 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Consider using `split()` instead of `split(' ')`.
Remember that `split()` without arguments splits on any whitespace and drops empty strings.
Then join the non-empty pieces with a single space.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.