def fix_line_breaks ( s ) : l = s . splitlines ( ) x = [ i . strip ( ) for i in l ] x = [ i for i in x if i ] # remove blank lines return "\n" . join ( x )
how to sstrip \r\n from list in python 3
Convert \ r \ n and \ r to \ n chars . Strip any leading or trailing whitespace on each line . Remove blank lines .
def fix_line_breaks(s):
    """
    Convert \r\n and \r to \n chars. Strip any leading or trailing whitespace
    on each line. Remove blank lines.
    """
    l = s.splitlines()
    x = [i.strip() for i in l]
    x = [i for i in x if i]  # remove blank lines
    return "\n".join(x)