I am a "neophyte python" and trying to understand the inner workings of the dictionary type. Last night, I tried to use it as a control structure (i.e., a switch statement) for keyboard input in openGL.
The problem was that for some reason, the dictionary continued to evaluate ALL cases (two in this case), and not just the one that was clicked.
Here is an example code snippet:
def keyboard(key): values = { 110: discoMode(), 27: exit() } values.get(key, default)()
I spent an hour or more last night trying to find the answer to the question why each "case" is evaluated, I have several ideas, but I could not clearly find the answer to the question "why."
So, would anyone be kind enough to explain to me why when I press the n key (the ascii view is 110), this part of the code also evaluates the record to 27 (ESC key)?
Sorry if this topic was beaten to death, but I looked and could not easily find the answer (maybe I missed it).
Thanks.
python data-structures switch-statement
Austen cameron
source share