title: How to replace repeated instances of a character with a single instance of that character in python
body: <p>I want to replace repeated instances of the <code>"*"</code> character within a string with a single instance of <code>"*"</code>. For example if the string is <code>"***abc**de*fg******h"</code>, I want it to get converted to <code>"*abc*de*fg*h"</code>.</p>
  
  <p>I'm pretty new to python (and programming in general) and tried to use regular expressions and string.replace() like:</p>
  
  <pre><code>import re    
  pattern = "***abc**de*fg******h"
  pattern.replace("*"\*, "*")
  </code></pre>
  
  <p>where <code>\*</code> is supposed to replace all instances of the "*" character. But I got: SyntaxError: unexpected character after line continuation character.</p>
  
  <p>I also tried to manipulate it with a for loop like:</p>
  
  <pre><code>def convertString(pattern):
  for i in range(len(pattern)-1):
      if(pattern[i] == pattern[i+1]):
          pattern2 = pattern[i]
  return pattern2
  </code></pre>
  
  <p>but this has the error where it only prints "*" because pattern2 = pattern[i] constantly redefines what pattern2 is...</p>
  
  <p>Any help would be appreciated.</p>