def search(self, string):
result = ""
if len(string) >= 4:
for book in self.collection:
if (string.lower() in book.get_title().lower):
result += str(book)
return result
I have a library class which has library.collection as a list of book objects, now I want to search the "string" and return the book I want, above are my code. the book class has method get_title() which returns the "title" of the book adn str(book) returns a string"book id: book title"
this works well, for example when I search "under" i got
10: Under the Net
11: Under the Net
117: Under the Skin
but I have two copies of the book "under the net"
I just want to find one of them, so for every string I search, if there are several copies of a book, I just want to add one of the str(book) to my result. can anyone help me with this?