Created
December 20, 2016 03:56
-
-
Save 0xLuz/1403058e39ab9235d58741264d68e3f6 to your computer and use it in GitHub Desktop.
How s python dispatcher works
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 avocado(key): | |
return key + ': Avocado' | |
def banana(key): | |
return key + ': Banana' | |
def cherry(key): | |
return key + ': Cherry' | |
def dispatcher(key): | |
dispatch = { | |
'a': avocado, | |
'b': banana, | |
'c': cherry | |
} | |
return dispatch[key](key) | |
# I should only pass the parameter here | |
# Otherwise all the funcions will be called on the dispatcher dict | |
print(dispatcher('a')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment