class A(object):

    def __init__(self):
        self.x = rand_str()
self.y = rand_str()

def __hash__(self):
    return hash(self.x)

def __eq__(self, other):
    return self.x == other.x
Python: Retrieve items from a set