I have some data that lends itself to representation as a value and a comparison function, (val, f), so another value can be checked against it by seeing if f(val, another) is True. That’s easy.
Some of them just need >, <, or == as f, however, and I can’t find a clean way of using them; I end up writing things like ScorePoint(60, lambda a, b: a <= b). That’s ugly.
Is there a way I can do something more like ScorePoint(60, <=)?
The
operatormodule is your friend:See http://docs.python.org/library/operator.html