(expression)
return out_stack[-1]
Calculate result of expression

    expression String: The expression
    type Type (optional): Number type [int, float]
Calculate result of expression
Calculate result of expression
def evaluate(expression):
    """
    Calculate result of expression

    expression String: The expression
    type Type (optional): Number type [int, float]
    """
    op_stack = deque()  # operator stack
    out_stack = deque()  # output stack (values)
    tokens = parse(expression)  # calls the function only once!
    for token in tokens:
        if numeric_value.match(token):
            out_stack.append(float(token))
        elif token == '(':
            op_stack.append(token)
        elif token == ')':
            while len(op_stack) > 0 and op_stack[-1] != '(':
                apply_operation(op_stack, out_stack)
            op_stack.pop()  # Remove remaining '('
        else:  # is_operator(token)
            while len(op_stack) > 0 and is_operator(op_stack[-1]) and higher_priority(op_stack[-1], token):
                apply_operation(op_stack, out_stack)
            op_stack.append(token)

    while len(op_stack) > 0:
        apply_operation(op_stack, out_stack)

    return out_stack[-1]
def evaluate ( expression ) : op_stack = deque ( ) # operator stack out_stack = deque ( ) # output stack (values) tokens = parse ( expression ) # calls the function only once! for token in tokens : if numeric_value . match ( token ) : out_stack . append ( float ( token ) ) elif token == '(' : op_stack . append ( token ) elif token == ')' : while len ( op_stack ) > 0 and op_stack [ - 1 ] != '(' : apply_operation ( op_stack , out_stack ) op_stack . pop ( ) # Remove remaining '(' else : # is_operator(token) while len ( op_stack ) > 0 and is_operator ( op_stack [ - 1 ] ) and higher_priority ( op_stack [ - 1 ] , token ) : apply_operation ( op_stack , out_stack ) op_stack . append ( token ) while len ( op_stack ) > 0 : apply_operation ( op_stack , out_stack ) return out_stack [ - 1 ]