code: def collapse_whitespace(message):
      
      return u' '.join(map(lambda s: s.strip(),
                           filter(None, message.strip().splitlines())))
docs: Collapses consecutive whitespace into a single space