If I had a list of some python class that had a string field, is there a way to compare a string to a list of objects of that class using in
? I was curious if there's a way to do something like this:
class Foo:
def __init__(self, s):
self.s = s
bar = Foo('test')
ls = [bar]
if 'test' in ls:
print("Yay!")
by modifying the __eq__
method, or maybe even there's an __in__
method I'm unaware of