Split string of expression
<p>I want to split string like</p>

<pre><code>Expression = "((((324+17)*3)/((936-51)+124))-((13*(72-41))+6))"
</code></pre>

<p>I use str.split() but it split the number like: "3 2 4 + 1 7"</p>

<p>output:</p>

<pre><code>"( ( ( ( 324 + 17 ) * 3 ) / ( ( 936 - 51 ) + 124 ) ) - ( ( 13 * ( 72 - 41 ) ) + 6 ) )"
</code></pre>

<p>You could use a dictionary to replace certain characters by their padded equivalents:</p>

<pre><code>&gt;&gt;&gt; Expression = "((((324+17)*3)/((936-51)+124))-((13*(72-41))+6))"
&gt;&gt;&gt; d = {'(':'( ', ')':' )', '+': ' + ', '-': ' - ', '*': ' * ', '/': ' / '}
&gt;&gt;&gt; ''.join(d[c] if c in d else c for c in Expression)
'( ( ( ( 324 + 17 ) * 3 ) / ( ( 936 - 51 ) + 124 ) ) - ( ( 13 * ( 72 - 41 ) ) + 6 ) )' 
</code></pre>

<p>Note that the padding dictionary pads <code>(</code> with one space to the right, <code>)</code> with one space to the left, and the operators by spacing on both sides. This prevents over-padding with nested parentheses.</p>

python