title: Evaluating infix expressions using stacks
body: <p>So I am currently learning about postfix, prefix, and infix expressions; and one of the challenge questions was about evaluating infix expressions using stacks. I think I understand the concept of it. However, I am really puzzled as to why my operators are not pushing onto my stack. I believe the problem is within line 31. However, I am not sure as to why. Could someone help me find and fix the problem?</p>
  
  <pre><code>class Stack:
  
      def __init__(self):
          self.items = []
  
      def is_empty(self):
          return self.items == []
  
      def push(self, item):
          self.items.append(item)
  
      def pop(self):
          return self.items.pop()
  
      def peek(self):
          return self.items[len(self.items) - 1]
  
      def size(self):
          return len(self.items)
  
      def infix(equation):
          prec_dictionary = {"(": 0, ")": 0, "^": 4, "*": 3, "/": 3, "+": 2, "-": 2, "&lt;": 1, "&gt;": 1} 
          operator_stack = Stack()
          operand_stack = Stack()
          allowed_operators = "+-/*^&lt;&gt;"
          a_list = equation.split()
          for i in a_list:
              if i in allowed_operators:
                  if operator_stack.is_empty():
                      operator_stack.push(i)
                  else:
                      if prec_dictionary[i] &gt; prec_dictionary[operator_stack.peek()]:
                          operator_stack.push(i)
              if i == "(":
                  operator_stack.push(i)
              elif i == ")":
                  while operator_stack.peek() != "(":
                      value1 = int(operand_stack.pop())
                      operator = operator_stack.pop()
                      value2 = int(operand_stack.pop())
                      value = compute(value1, value2, operator)
                      operand_stack.push(value)
                  operator_stack.pop()
              else:
                  operand_stack.push(i)
          return operand_stack.pop()
  
      def compute(number1, number2, operator):
          if operator == "+":
              return number1 + number2
          elif operator == "-":
              return number1 - number2
          elif operator == "*":
              return number1 * number2
          elif operator == "/":
              return number1 / number2
          elif operator == "^":
             return number1 ** number2
          elif operator == "&lt;":
              return min(number1, number2)
          else:
              return max(number1, number2)    
  
      print(infix('2 ^ ( 1 + 3 ^ 2 )'))
  </code></pre>