Philosophy | Artificial Intelligence | etcetera
Welcome to my personal space on the web ↯.
Selecting user commands in style (Python)
If you write an interactive program that takes user commands as an input, you can select the appropriate action for a given command by going through a sequence of if... else if statements. But if you write in Python, there’s always a cooler way to do things. A method I like personally in this situation is defining a dictionary where the keys are the command strings, and the corresponding values are lambda expressions.
See archives for more ...