title: Replace multi-spacing in strings with single whitespace - Python
body: <p>The overhead in looping through the string and replacing double spaces with single ones is taking too much time. Is a faster way of trying to replace multi spacing in strings with a single whitespace?</p>
  
  <p>I've been doing it like this, but it's just way too long and wasteful:</p>
  
  <pre><code>str1 = "This is    a  foo bar   sentence with  crazy spaces that  irritates   my program "
  
  def despace(sentence):
    while "  " in sentence:
      sentence = sentence.replace("  "," ")
    return sentence
  
  print despace(str1)
  </code></pre>