Skip to content

Instantly share code, notes, and snippets.

@alaudet
Created May 4, 2015 14:56
Show Gist options
  • Save alaudet/e67452c140bac851d9c7 to your computer and use it in GitHub Desktop.
Save alaudet/e67452c140bac851d9c7 to your computer and use it in GitHub Desktop.
Using Dicts instead of large if, elif statements
# Example of using a dict instead of numerous if/elif statements.
handlers = {
"A": funtion_one,
"B": function_two,
"C": function_three,
"D": function_four,
"E": exit
}
answer = input("> ")
if answer in handlers.keys():
handlers[answer]() #These brackets call the function it's pulled out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment