Source

dictionary_switches / code / TableDriven / switch_function.py

Full commit
def switch( on, mapping, default=None ):
    try:
        return mapping[on]
    except Keyerror as e:
        return default

foo = switch( "test", {
        "test": "you hit test",
        "bar": "you hit bar"
    })

print(foo)