Created
April 26, 2016 19:02
-
-
Save ivancorrales/62b5ce1ac0255a0ef71e0be7030ba4f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from models.model import Book | |
class BookDB: | |
ID = 0 | |
def __init__(self): | |
self.books = [] | |
self.insert(Book('Don Quijote de la Mancha', 'Miguel de Cervantes')) | |
self.insert(Book('Romeo y Julieta', 'William Shakespeare')) | |
def insert(self,book): | |
self.ID+=1 | |
book.id = self.ID | |
self.books.append(book) | |
def all(self): | |
return self.books | |
def one(self,bookId): | |
result = next(filter(lambda book: book.id == bookId,self.books),None) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment