Python - Switch/Case Substitute
Last Updated: 1743Z 23SEP19
(Created: 1743Z 23SEP19)
Use a dictionary and function pointers as a substitute for switch/case.
Signatures:
None
Examples:
import operator
def apply_operation(left_operand, right_operand, operator):
import
op_map = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.truediv
}
return op_map[operator](left_operand, right_operand)