def _calculate(numbers, symbols):
        """Calculates a final value given a set of numbers and symbols."""
        if len(numbers) is 1:
            return numbers[0]

        precedence = [[pow], [mul, div], [add, sub]]

        # Find most important operation
        for op_group in precedence:
            for i, op in enumerate(symbols):
                if op in op_group:
                    # Apply operation
                    a = numbers[i]
                    b = numbers[i + 1]
                    result = MathService._applyBinary(a, b, op)
                    new_numbers = numbers[:i] + [result] + numbers[i + 2:]
                    new_symbols = symbols[:i] + symbols[i + 1:]

                    return MathService._calculate(new_numbers, new_symbols)
def _calculate ( numbers , symbols ) : if len ( numbers ) is 1 : return numbers [ 0 ] precedence = [ [ pow ] , [ mul , div ] , [ add , sub ] ] for op_group in precedence : for i , op in enumerate ( symbols ) : if op in op_group : a = numbers [ i ] b = numbers [ i + 1 ] result = MathService . _applyBinary ( a , b , op ) new_numbers = numbers [ : i ] + [ result ] + numbers [ i + 2 : ] new_symbols = symbols [ : i ] + symbols [ i + 1 : ] return MathService . _calculate ( new_numbers , new_symbols )
Calculates a final value given a set of numbers and symbols.