Using a switch-like if/else construct versus a dictionary?
Klaas
mike.klaas at gmail.com
Mon Jun 25 16:34:00 EDT 2007
On Jun 19, 12:40 pm, asincero <asinc... at gmail.com> wrote:
> Which is better: using an if/else construct to simulate a C switch or
> use a dictionary? Example:
Whichever results in the clearest code that meets the performance
requirements.
FWIW, if you define the dictionary beforehand, the dict solution is
O(1) while if/else is O(N), which can be important.
-Mike
More information about the Python-list
mailing list