Created
April 5, 2013 16:44
-
-
Save rturowicz/5320762 to your computer and use it in GitHub Desktop.
switch implementation
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
'''switch implementation''' | |
def a(what): | |
print what | |
def switch(what): | |
try: | |
{'1' : lambda : a('one'), | |
'2' : lambda : a('two') | |
}[what]() | |
except KeyError, e: | |
print "Key not found: ", e | |
if __name__ == "__main__": | |
switch('1') | |
switch('2') | |
switch(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment