Python solution with operator dictionary


#1
def evalRPN(self, tokens):
    ops = { "+": (lambda a, b: a + b),
          "-": (lambda a, b: a - b),
          "*": (lambda a, b: a * b),
          "/": (lambda a, b: a / b)
            }

    # tokens = expression.split()
    stack = []
    
    for token in tokens:
        if token in ops:
          arg2 = stack.pop()
          arg1 = stack.pop()
          result = ops[token](arg1, arg2)
          stack.append(int(result))
        else:
          stack.append(int(token))
    
    return stack.pop()