title: Python: How to sort the letters of a string keeping some characters in place?
body: <p>I've already asked this question, but it was for <a href="https://stackoverflow.com/questions/40911995/ruby-how-to-sort-a-string-keeping-some-characters-in-place">Ruby</a>, now it's Python's turn!
  I want to sort the words of a string, keeping non-alphanumeric characters in place, for example:</p>
  
  <pre><code>"hello, sally! seen 10/dec/2016 =&gt; ehllo, allsy! eens 01/cde/0126"
  </code></pre>
  
  <p>Based in the answer I've previously received, I've tried to do:</p>
  
  <pre><code>def sortThisList(listWords):
      for word in listWords:
          print(re.sub('\W+', sortStr(word), word)) #Error
  
  def sortStr(word):
      return "".join(sorted(list(word)))
  </code></pre>
  
  <p><strike>But this error pops up:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "&lt;stdin&gt;", line 3, in sortItAll
    File ".../lib/python3.6/re.py", line 191, in sub
      return _compile(pattern, flags).sub(repl, string, count)
  TypeError: expected string or bytes-like object
  </code></pre>
  
  <p></strike></p>
  
  <p>Not anymore, thank you ^^.
  But it's still not sorting properly.</p>