Is it possible to do something that looks like this:
if obj in a_list_of_the_same_obj_type:
#do stuff
My obj already have the __eq__ and __ne__ function that compare on an attribute so I thought the in keyword would call it but it doesn't look like it does.
In this case, operator 'in' calls the __contains__() of python´s built-in list object which then calls the __eq__() of your object, so make sure that the __eq__() dunder method in your obj-class is properly implemented.
You need to implement __contains__ to be able to test for membership
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With