I have a class that builds a list of objects. I am confused at my inability to identify objects within a list by value. I kind of get I have two separate instances and the instance I am looking for in the list doesn't exist.
So whats the best way to find an object in a list of objects by value?
Code:
class simple():
def __init__(self, a, b):
self.a = a
self.b = b
def __str__(self):
return str(self.a) + ":" + str(self.b)
class abstract():
def __init__(self):
self.l = [
simple(1, 2),
simple(2, 3)
]
def __iter__(self):
return iter(self.l)
if __name__ == "__main__":
a1 = abstract()
s1 = simple(1, 2)
print(a1.l[0] in a1.l) # True
print(s1 in a1) # False
print(s1 in a1.l) # False
print(s1 == a1.l[0]) # False
print(str(s1), str(a1.l[0])) # Object values are equal, but found