Created
May 4, 2015 14:56
-
-
Save alaudet/e67452c140bac851d9c7 to your computer and use it in GitHub Desktop.
Using Dicts instead of large if, elif statements
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
# 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