Код: Выделить всё
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
def __eq__(self, other):
return isinstance(other, Book) and self.title == other.title and self.author == other.author
def __hash__(self):
return hash((self.title, self.author))
book1 = Book("Wings of Fire", "A.P.J. Abdul Kalam")
book2 = Book("Wings of Fire", "A.P.J. Abdul Kalam")
books_dict = {book1: "Autobiography"}
print(book2 in books_dict)
Подробнее здесь: https://stackoverflow.com/questions/796 ... implementi