Skip to content

Instantly share code, notes, and snippets.

@LotusChing
Created November 2, 2016 07:15
Show Gist options
  • Save LotusChing/944eadbfef885f54f750c9db358aa3be to your computer and use it in GitHub Desktop.
Save LotusChing/944eadbfef885f54f750c9db358aa3be to your computer and use it in GitHub Desktop.
Case in Python
matrix = {
'+': lambda x, y: x + y,
'-': lambda x, y: x - y,
'*': lambda x, y: x * y,
'/': lambda x, y: x / y
}
def compute(x, oper, y):
return matrix[oper](x, y)
print(compute(1, '*', 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment