This function removes leading and trailing whitespace and collapses all internal sequences of whitespace characters (spaces, tabs, newlines) into single spaces. This is particularly useful for cleaning free-text survey responses that may contain inconsistent formatting.
Parameters
Name
Type
Description
Default
text
str or None
The text string to clean. If None is provided, the function returns None.
required
Returns
Name
Type
Description
str or None
The cleaned text with normalized whitespace. Returns None if input is None.
Raises
Name
Type
Description
TypeError
If the input is not a string or None.
Examples
>>> handle_emptyStrings(" Hello World ")'Hello World'