code: def replace_whitespace(text, SAFE_SPACE='|<^>|', insert=True):
      
      if insert:
          # replace whitespace with safe space chr
          args = (' ', SAFE_SPACE)
      else:
          # replace safe space chr with whitespace
          args = (SAFE_SPACE, ' ')
  
      return '\n'.join(line.strip().replace(*args)
                       for line in str.splitlines(text))
docs: Replace non-strippable whitepace in a string with a safe space