56
Dispatch Tables in Python

Dispatch Tables in Python

5 years ago
Anonymous $L9wC17otzH

https://medium.com/@andreacolangelo/dispatch-tables-in-python-d37bcc443b0b

Andrea ColangeloBlockedUnblockFollowFollowingDec 23Photo by Chris Ried on UnsplashHave you ever needed to run different functions according to the value of a variable? This first approach that comes to mind would probably be a long series of if-elif statements resembling a C-style switch case. Well, there is a better option: a dispatch table.

A dispatch table in Python is basically a dictionary of functions. This concept is not Python-specific indeed, rather quite common in Computer Science:

Dispatch Tables in Python

Dec 26, 2018, 1:15pm UTC
https://medium.com/@andreacolangelo/dispatch-tables-in-python-d37bcc443b0b > Andrea ColangeloBlockedUnblockFollowFollowingDec 23Photo by Chris Ried on UnsplashHave you ever needed to run different functions according to the value of a variable? This first approach that comes to mind would probably be a long series of if-elif statements resembling a C-style switch case. Well, there is a better option: a dispatch table. > A dispatch table in Python is basically a dictionary of functions. This concept is not Python-specific indeed, rather quite common in Computer Science: