Untitled
unknown
plain_text
a year ago
1.8 kB
12
Indexable
class Book:
def __init__(self, title, author, description, series=None):
self.title = title
self.author = author
self.description = description
self.series = series # Reference to a Series object if the book is part of a series
def __str__(self):
return "Book"
# Create Books
book1 = PhysicalBook("Harry Potter and the Philosopher's Stone", "J.K. Rowling", "First book of Harry Potter", "978-3-16-148410-0", harry_potter_series)
book2 = Ebook("Harry Potter and the Chamber of Secrets", "J.K. Rowling", "Second book of Harry Potter", harry_potter_series)
books= [book1, book2]
def getBookFiltered(books, title, author):
"""
"""
ans=[]
for book in books:
if book.title.lower()==title.lower():
ans.append(book)
ans1=[]
for book in ans:
if book.author.lower()==author.lower():
ans1.append(book)
return ans1
class Condition:
def validate(book):
"""
"""
pass
class TitleCondition(Condition):
def __init__(self, title):
self.title=title
def validate(book):
return self.book.title.lower()==title.lower()
class AuthorCondition(Condition):
def __init__(self, author):
self.author=author
def validate(book):
return self.book.author.lower()==author.lower()
def getbookFiltered(books, listOfConditions):
tmpList=books
for condition in listOfConditions:
tmp = []
for book in tmpList:
if condition.validate(book):
tmp.append(book)
tmpList=tmp
return tmpList
conditions=[AuthorCondition("JKRowling"), TitleCondition("someTitle")]
getbookFiltered(books, conditions)
getbookFiltered(books, "JKRowling", "someTitle", "isbn")
Editor is loading...
Leave a Comment