-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.py
More file actions
26 lines (22 loc) · 771 Bytes
/
Library.py
File metadata and controls
26 lines (22 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
class Library:
def __init__(self, name):
self.name = name
self.books = []
def add_book(self, book):
self.books.append(book)
def remove_book(self, book):
kept_books = []
for b in self.books:
if b.title != book.title or b.author != book.author:
kept_books.append(b)
self.books = kept_books
def search_books(self, search_string):
string_match = []
for b in self.books:
if search_string.casefold() in b.title.casefold() or search_string.casefold() in b.author.casefold():
string_match.append(b)
return string_match