Skip to content

Instantly share code, notes, and snippets.

@umstek
Created July 31, 2016 17:22
Show Gist options
  • Save umstek/3a356406c2d3b487c33be4386c724d7e to your computer and use it in GitHub Desktop.
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.
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