In Python, how can I pass an operator like + or < as a parameter to a function which expects a comparison function as a parameter?
def compare (a,b,f):
return f(a,b)
I have read about functions like __gt__() or __lt__() but still I was not able to use them.
The operator module is what you are looking for.
There you find functions that correspond to the usual operators.
e.g.