Hi guys!
I have a small problem, i can’t verbally explain the problem, so i’ll just try to illustrate it in code:
class move(object):
def __init__(self, number):
self.number = number
list1 = [move(1), move(2), move(3), move(4)]
list2 = [move(3), move(7)]
list1.remove(list2[0])
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
list1.remove(list2[0])
ValueError: list.remove(x): x not in list
As you can see, list1[2] and list2[0] are both derived from the same class and have the exact same attributes, they are only two different instances of this class
What is the optimal solution to this problem?
Thank you very much for your help!
You should override the
__eq__of your class to tell Python that two classes are equal if their numbers are equal: