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>I think what you nee is  to insert space in between every non numeric characters. Split wont be able to do the that job for you and you could use re.sub for the same.</p>

<p>This is what I could come up quickly and there could be better expression to do this in single iteration but it will give you a idea </p>

<pre><code>import re
Expression = "((((324+17)*3)/((936-51)+124))-((13*(72-41))+6))"
# Insert space after every non numeric characters
str = re.sub("([^0-9])", r'\1 ', Expression).strip()
#Insert space after numeric characters which are followed by non numeric characters
str = re.sub("([0-9])([^0-9])", r'\1 \2', str).strip()
print(str)
</code></pre>

<p><strong>Output</strong><br>
    <code>( ( ( ( 324 + 17 ) * 3 ) / ( ( 936 - 51 ) + 124 ) ) - ( ( 13 * ( 72 - 41 ) ) + 6 ) )</code></p>

python