Last active
August 29, 2015 14:25
-
-
Save joelgrus/1b726fc49f52946ae710 to your computer and use it in GitHub Desktop.
stealing an idea from trenthauck
This file contains 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
# got the idea from https://gist.github.com/tshauck/6ebb0c2d6adc667608b8 | |
def switch(*args, default=None): | |
try: | |
return next(value for cond, value in args if cond) | |
except StopIteration: | |
return default | |
x = 1 | |
y = switch((x > 10, "more than 10"), | |
(x > 1, "more than 1"), | |
(x > 0, "more than 0"), | |
default="hooray!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment