Skip to content

Instantly share code, notes, and snippets.

@rturowicz
Created April 5, 2013 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rturowicz/5320762 to your computer and use it in GitHub Desktop.
Save rturowicz/5320762 to your computer and use it in GitHub Desktop.
switch implementation
'''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