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:

Last Seen
18 minutes ago
Reputation
0
Spam
0.000
Last Seen
11 minutes ago
Reputation
0
Spam
0.000
Last Seen
55 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
16 minutes ago
Reputation
0
Spam
0.000
Last Seen
4 minutes ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
6 hours ago
Reputation
0
Spam
0.000
Last Seen
4 minutes ago
Reputation
0
Spam
0.000
Last Seen
19 minutes ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
57 minutes ago
Reputation
0
Spam
0.000
Last Seen
46 minutes ago
Reputation
0
Spam
0.000
Last Seen
47 minutes ago
Reputation
0
Spam
0.000
Last Seen
28 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
46 minutes ago
Reputation
0
Spam
0.000
Last Seen
47 minutes ago
Reputation
0
Spam
0.000
Last Seen
7 minutes ago
Reputation
0
Spam
0.000
Last Seen
50 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
42 minutes ago
Reputation
0
Spam
0.000
Last Seen
38 minutes ago
Reputation
0
Spam
0.000
Last Seen
53 minutes ago
Reputation
0
Spam
0.000
Last Seen
41 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
12 minutes ago
Reputation
0
Spam
0.000
Last Seen
7 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
26 minutes ago
Reputation
0
Spam
0.000
Last Seen
15 minutes ago
Reputation
0
Spam
0.000
Last Seen
13 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
57 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
4 minutes ago
Reputation
0
Spam
0.000
Last Seen
51 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
3 hours ago
Reputation
0
Spam
0.000
Last Seen
37 minutes ago
Reputation
0
Spam
0.000
Last Seen
24 minutes ago
Reputation
0
Spam
0.000
Last Seen
a few minutes ago
Reputation
0
Spam
0.000
Last Seen
57 minutes ago
Reputation
0
Spam
0.000
Last Seen
17 minutes ago
Reputation
0
Spam
0.000
Last Seen
a few minutes ago
Reputation
0
Spam
0.000