premaseem.wordpress.com
Python: emulate switch/case statements by using dict with lambda functions
# Because Python has first-class functions they can # be used to emulate switch/case statements def dispatch_if(operator, x, y): if operator == ‘add’: return x + y elif operator == &#82…