Sorting strings with numbers in Python
<p>I have this string: </p>

<pre><code>string = '9x3420aAbD8'
</code></pre>

<p>How can I turn string into:</p>

<pre><code>'023489ADabx'
</code></pre>

<p>What function would I use?</p>

<p>You can use the <code>sorted()</code> function to sort the string, but this will return a list</p>

<pre><code>sorted(string)
['0', '2', '3', '4', '8', '9', 'A', 'D', 'a', 'b', 'x']
</code></pre>

<p>to turn this back into a string you just have to join it, which is commonly done using <code>''.join()</code></p>

<p>So, all together:</p>

<pre><code>sorted_string = ''.join(sorted(string))
</code></pre>

python string sorting