An improvement on the switch-using-dictionaries example: instead of doing this...
keycode = 2
functions = {1: key_1_pressed, 2: key_2_pressed, 3: key_3_pressed}
if functions.has_key(keycode):
functions[keycode]()
else:
unknown_key_pressed()
you can save three lines by replacing the if-else block with: functions.get(keycode, unknown_key_pressed)()