In Python 3, I have a list (my_array
) that contains an instance of the Demo
class with a certain attribute set on that instance. In my case, the attribute is value: int = 4
.
Given an instance of the Demo
class, how can I determine if that instance already exists in my_array
with the same properties. Here's a MCRE of my issue:
from typing import Listclass Demo: def __init__(self, value: int): self.value = valuemy_array: List[Demo] = [Demo(4)]print(Demo(4) in my_array) # prints False
However, Demo(4)
clearly already exists in the list, despite that it prints False
.
I looked through the Similar Questions, but they were unrelated.
How can I check if that already exists in the list?