edit: I changed the title from complement to converse after the discussion below.
In the operator module, the binary functions comparing objects take two parameters. But the contains function has them swapped.
I use a list of operators, e.g. operator.lt, operator.ge.
They take 2 arguments, a and b.
I can say operator.lt(a, b) and it will tell me whether a is less than b.
But with operator.contains, I want to know whether b contains a so I have to swap the arguments.
This is a pain because I want a uniform interface, so I can have a user defined list of operations to use (I'm implementing something like Django QL).
I know I could create a helper function which swaps the arguments:
def is_contained_by(a, b):
return operator.contains(b, a)
Is there a "standard" way to do it?
Alternatively, I can implement everything backwards, except contains. So map lt to ge, etc, but that gets really confusing.