Created
July 6, 2020 09:16
-
-
Save sum-catnip/9cca763b3bb0fd7b32f3e909e082f47a to your computer and use it in GitHub Desktop.
the legendary python switch case
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
def switch(target, dict): | |
for k, v in dict.items(): | |
# could add pattern matching memes here | |
# instead of just equals | |
# or maybe the key could be a callable too which will return true or false | |
# that kinda would just be an if tho | |
if k == target: | |
v(target) | |
break | |
switch(1, { | |
15: lambda x: print(15), | |
'kektop': lambda x: print('kektop'), | |
1: lambda x: print('yeet'), | |
"1": lambda x: print('oof') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment