Created
December 21, 2014 20:12
-
-
Save Higgs1/369c249f7f4bd7ab2244 to your computer and use it in GitHub Desktop.
Python switch statement
This file contains hidden or 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
class switch: | |
def __init__(_,o):_._,_.o=0,o | |
def __iter__(_):yield _.__ | |
def __(_,*o): | |
if _._ or not o:return 1 | |
elif _.o in o:_._=1;return 1 | |
""" | |
Usage: | |
import string | |
c = input('please enter a character: ') | |
for case in switch(c): | |
if case(*string.ascii_lowercase): | |
print("c is lowercase!") | |
break | |
if case(*string.ascii_uppercase): | |
print("c is uppercase!") | |
break | |
if case('!', '?', '.'): | |
print("c is a sentence terminator!") | |
break | |
if case(): | |
print("I dunno what c was!") | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment