title: In-place way of trimming & removing extra whitespace from a string
body: <p>Looking for a way to remove extra whitespace from a large python string (100MB+) without making copies. Tried using <code>ctypes</code> but it seems like you have to convert the string to <code>bytes</code> for <code>ctypes.memmove</code> to work.</p>
  <p>I need a function <code>remove_extra_whitespaces</code> that can do this in O(1) memory</p>
  <pre class="lang-py prettyprint-override"><code>&gt;&gt; a = '  hello   world'
  &gt;&gt; a = remove_extra_whitespaces(a)
  &gt;&gt; a == 'hello world'
  True
  </code></pre>
  <p>Is there a library or something else that I can use for this task?</p>