Evaluate Array of operators and numbers in Python
<p>I have a program that produces arrays of numbers and operators, like this:<code>[1,'+',6,'*',3,'*',2]</code>
What I would like to do is to evaluate this kind of array for its numerical value using order of operations. The array length may very, but they will always begin and end with a number and a number will not follow a number and an operator will not follow an operator.<br>
I think I can use the <code>operator</code> module for converting the operator strings into actual operations, but I don't know how to manage the order of operations part.</p>

<p>You might try this, pretty naive though.</p>

<pre><code>a = [1,'+',6,'*',3,'*',2]
source = ''
for i in a:
    source += str(i)
print eval(source)  # 37
</code></pre>

python arrays