John Nagle wrote: > Python doesn't have a "switch" or "case" statement, and when > you need a state machine with many states, that makes for painful, > slow code.
Cython has a built-in optimisation that maps if-elif-else chains to C's switch statement if they only test a single int/char variable, even when you write things like "elif x in [1,5,9,12]". This works in Cython, because we know that the comparison to a C int/char is side-effect free. It may not always be side-effect free in Python, so this won't work in general. It would be perfect for your case, though. Stefan -- http://mail.python.org/mailman/listinfo/python-list