title: Insert spaces before and after special symbols in python
body: <p>I want preprocess strings using Python.
  Here is an example. </p>
  
  <p>Given a string</p>
  
  <pre><code>string = "hello... (world)!"
  </code></pre>
  
  <p>I want to insert spaces before and after special characters like</p>
  
  <pre><code>desired_string = "hello . . . ( world ) !"
  </code></pre>
  
  <p>I find a way to do this by replace function.</p>
  
  <pre><code>string = string.replace(".", " . ")
  string = string.replace("(", " ( ")
  string = string.replace(")", " ) ")
  string = string.replace("!", " ! ")
  </code></pre>
  
  <p>Then, </p>
  
  <pre><code>&gt;&gt;&gt; string
  'hello .  .  .   ( world )  ! '
  </code></pre>
  
  <p>(This output string has more spaces than desired_string but is acceptable because I well apply <code>.split</code> method later.)</p>
  
  <p>But the code is lengthy especially when many types of symbols appear. (e.g. !, @, $, %, &amp;, ....)</p>
  
  <p>I think there is a better way (maybe using <code>re.sub</code> ?) Does anybody can show a better code?</p>