Equal But Unfindable
class CaseInsensitiveStr:
def __init__(self, s):
self.s = s
def __eq__(self, other):
return self.s.lower() == other.s.lower()
def __hash__(self):
return hash(self.s) # not lowercased
catalog = {CaseInsensitiveStr("Widget"): 42}
print(CaseInsensitiveStr("Widget") == CaseInsensitiveStr("WIDGET"))
print(CaseInsensitiveStr("WIDGET") in catalog)
What does this print?
Sign in to answer questions and track your progress
Sign In