Not _quite_ equivalent to what simont had originally:
>>> class foo:
... def __cmp__(self, other):
... if other is True: return 0
... if other is False: return 0
... return 1
...
>>> f = foo()
>>> g = foo()
>>> f == g
False
>>> d = {}
>>> d[5] = f
>>> d.get(6, not f) == f
True
>>> 6 in d and d[6] == f
False
Note cmp is -1,0,1 for less than/equal/greater than.
Yes, I think that clever as ptc24's counterexample is (and doubly so because I tried to construct a similar thing and didn't quite get it to work), it falls into the same category as cartesiandaemon's question about NaN: if you define a class which has deliberately weird behaviour when compared, then you've violated the warranty of any of these methods once you try to use an instance of that class as a key or value in the dictionary or as a key or value to test for. It's only fair game to use it as the dummy non-value.
>>> class foo: ... def __cmp__(self, other): ... if other is True: return 0 ... if other is False: return 0 ... return 1 ... >>> f = foo() >>> g = foo() >>> f == g False >>> d = {} >>> d[5] = f >>> d.get(6, not f) == f True >>> 6 in d and d[6] == f FalseNote cmp is -1,0,1 for less than/equal/greater than.