Archive

Simple Python Function to Remove White-Space not Included in Quotes

Python function to remove white-space outside quotes:

import re
def cleanWhite(text):
    parts = re.split(r"""("[^"]*"|'[^']*')""", text)
    parts[::2]= map(lambda s:"".join(s.split()), parts[::2])# outside quotes    return("".join(parts))