Skip to content

Instantly share code, notes, and snippets.

@JoabMendes
Created December 20, 2016 03:56
Show Gist options
  • Save JoabMendes/1403058e39ab9235d58741264d68e3f6 to your computer and use it in GitHub Desktop.
Save JoabMendes/1403058e39ab9235d58741264d68e3f6 to your computer and use it in GitHub Desktop.
How s python dispatcher works
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