I was wondering if someone could tell me the pythonic way to check out the following.
I have a 6 bit binary number and want to check with its decimal values. Using mathe
Use a dictionary mapping values into outcomes (which can be functions in Python).
For example:
d = {}
d[0] = ....
d[1] = ....
d[2] = ....
outcome = d[a]
Naturally, how this works depends on your ....
, but this construct can be very flexible. The most important feature of this approach is that this dictionary can be populated programmatically, and you don't need to write a lot of manual assignments. It's of course also much more efficient than going over many values with nested if
statements (or elsif
)