class MyObject(object):

    def __init__(self, data):
        self.data = data

def __cmp__(self, other):
    return self.data - other.data

def __hash__(self):
    return hash(self.data)
a = MyObject(5)
Understanding python object membership for sets