Skip to content

Instantly share code, notes, and snippets.

View tiabas's full-sized avatar

Kevin Mutyaba tiabas

View GitHub Profile
@tiabas
tiabas / parse_math_expression.py
Last active December 18, 2023 06:37
Parse Math Expression
# Simple Shunting-Yard solution
#
# Given a math expression, parse and evaluate
# the expression
#
# E.g '2+1' => 3, 8/2*4+1 => 17, 2+(1*2) = 4, ((2+4)/2*7) => 21
#
def parse_math_expression(exp):
PRECENDENCE = {
')': 3,