For this, you can also define the __eq__ method, which will be preferred to __cmp__ for equallity tests while still using __cmp__ for searching / comparisons.