3 ms·
Python doesn't need a switch or case statement because you can write a suite of ad-hoc functions, stick them in a dictionary with your values as keys, and dispa
by candeira 15y ago
Python doesn't need a switch or case statement because you can write a suite of ad-hoc functions, stick them in a dictionary with your values as keys, and dispatch on the values:
>>> def first():
... print "a"
...
>>> def second():
... print "beta"
...
>>> caseof = {1: first, 2: second}
>>> caseof[1]()
a
>>> caseof[2]()
beta
>>>