Install and update using pip:
pip install python-switch
from python_switch import Switch
s = Switch({"d":lambda x:f"returns {x} (d)","default":lambda x: f"returns {x} (default)"})
print(s.get("d")(1))
Adding a case later.
from python_switch import Switch
s = Switch({"default":lambda x: f"returns {x} (default)"})
s.addCase("d",lambda x:f"returns {x} (d)")
print(s.get("d")(1))
Adding cases with the decorator.
from python_switch import Switch
s = Switch({"default":lambda x: f"returns {x} (default)"})
@s.case()
def d(x):
return f"returns {x} (d)"
print(s.get("d")(1))