Created
July 31, 2016 17:22
-
-
Save umstek/3a356406c2d3b487c33be4386c724d7e to your computer and use it in GitHub Desktop.
A switch control structure, as an expression, implemented in python3 without using any control structures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print( | |
( | |
lambda value, cases, default: | |
{ | |
True: lambda: cases[value], | |
False: lambda: default | |
}[value in cases]() | |
)( | |
int(input()), {1: 'case 1', 2: 'case 2', 3: 'case 3'}, 'default' | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment