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 ...
↬ For later reference, if I ever consider self-hosting a mailing service.
Filosoof Ton Lemaire leeft radicaal eenvoudig
↬ ‘Op deze aarde is geen onschuldig verblijf mogelijk’