Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. #!/usr/bin/env python3.0
  2.  
  3. def switch(value, d):
  4.     try:
  5.         d[value]()
  6.     except KeyError:
  7.         d["default"]()
  8.  
  9. def my_switch(value):
  10.     switch(value, {
  11.         1 : (lambda: print("hello")),
  12.         2 : (lambda: print("goodbye")),
  13.         "default" : (lambda: print("default"))
  14.     })
  15.  
  16. my_switch(1)
  17. my_switch(2)
  18. my_switch(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement