title: Parsing maths expression
body: <p>So the following code with the function: "eqn" converts a string: "d" that is a mathematical expression, into a list of its integers and operators according to Reverse Polish Notation, where "add", "subtract", "multiply" and "divide" represent +, -, * and / respectively. There is also the "negate" operator which takes any positive integer and turns it into a negative integer. Example inputs and outputs:</p>
  
  <ul>
  <li>eqn("10 5 add") should produce an output of [10, 5 and "add"]</li>
  <li>eqn("5 6 add 2 negate divide") should produce an output of [5, 6, "add", -2, "divide"]</li>
  </ul>
  
  <p>With the negative function though, if it is not used correctly (not after a number) then the function should return the index number of the first incorrect "negate". </p>
  
  <p>For example:</p>
  
  <ul>
  <li>eqn("negate 2 add 2") should produce an output of 0</li>
  <li><p>eqn("2 4 add negate") should produce an output of 3</p>
  
  <pre><code>def eqn(d):
   extrac = []
  
  for e in eqnStr.split():
   if len(e) == 0:
      continue
  
   try:
      extrac.append(int(e))
      continue
   except ValueError:
      pass
  
   try:
      extrac.append(float(e))
      continue
   except ValueError:
      pass
  
  extrac.append(e)
  
  return extrac
  </code></pre></li>
  </ul>
  
  <p>The problem is that the negate function won't work. Instead of changing the integer to a negative it just comes out as "negate" in the output when essentially it should 'disappear'. For example: </p>
  
  <p>eqn("5 6 add 2 negate divide") should produce an output of [5, 6, "add", -2, "divide"] but instead produces [5, 6, "add", 2, "negate", "divide"] How do I fix this and how do I get it to show the index number of the first invalid negate?</p>