I have a class with a custom hash method.
class Test(object):
def __init__(self, key, value):
self.key = key
self.value = value
def __hash__(self):
return hash(self.key)
I do a setusing objects of this class.
t0, t1, t2 = Test(0, 10), Test(1, 5), Test(2, 10)
s = set([t0, t1, t2])
Now, is there a way to find objects from susing key? that is, I want:
find_using_key(s, 1)
I know that I can do this by sorting through the elements in the set, but I feel that there must be an O (1) method for this, since it keyeffectively determines the "position" in set.
source
share