This is the Python `bool`, and you're right in that it would be significantly slower if you were looking it up every time.

You could experiment with the Cython `bint`, though, which is a C `int` but gets coerced into `True` or `False` by Cython. It could be fast enough to allow non-duplicated loops...