If there are only three operators, I would not try anything more complicated. Maybe if there were many more you could try a dict, where the key is operator and the value is a comparing function.