def clean_whitespace ( statement ) : import re # Replace linebreaks and tabs with spaces statement . text = statement . text . replace ( '\n' , ' ' ) . replace ( '\r' , ' ' ) . replace ( '\t' , ' ' ) # Remove any leeding or trailing whitespace statement . text = statement . text . strip ( ) # Remove consecutive spaces statement . text = re . sub ( ' +' , ' ' , statement . text ) return statement
remove forward whitespace python
Remove any consecutive whitespace characters from the statement text .
def clean_whitespace(statement):
    """
    Remove any consecutive whitespace characters from the statement text.
    """
    import re

    # Replace linebreaks and tabs with spaces
    statement.text = statement.text.replace('\n', ' ').replace('\r', ' ').replace('\t', ' ')

    # Remove any leeding or trailing whitespace
    statement.text = statement.text.strip()

    # Remove consecutive spaces
    statement.text = re.sub(' +', ' ', statement.text)

    return statement