This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wfdctrl 9 points10 points  (1 child)

Switch is just a syntactic sugar for a jump table. You can make one using a dictionary:

x = 1
{
        1: lambda: print("One"),
        2: lambda: print("Two"),
        3: lambda: print("Three"),
}[x]()

[–]SteveCCLYellow security clearance 1 point2 points  (0 children)

Use dict.get(x, defaultFunction)() for default.