-
Notifications
You must be signed in to change notification settings - Fork 131
/
bookdb.py
45 lines (41 loc) · 1.46 KB
/
bookdb.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class BookDB():
def titles(self):
titles = [
dict(id=id, title=database[id]['title']) for id in database.keys()
]
return titles
def title_info(self, id):
return database.get(id, None)
# let's pretend we're getting this information from a database somewhere
database = {
'id1': {
'title': 'CherryPy Essentials: Rapid Python Web Application Development',
'isbn': '978-1904811848',
'publisher': 'Packt Publishing (March 31, 2007)',
'author': 'Sylvain Hellegouarch',
},
'id2': {
'title': 'Python for Software Design: How to Think Like a Computer Scientist',
'isbn': '978-0521725965',
'publisher': 'Cambridge University Press; 1 edition (March 16, 2009)',
'author': 'Allen B. Downey',
},
'id3': {
'title': 'Foundations of Python Network Programming',
'isbn': '978-1430230038',
'publisher': 'Apress; 2 edition (December 21, 2010)',
'author': 'John Goerzen',
},
'id4': {
'title': 'Python Cookbook, Second Edition',
'isbn': '978-0-596-00797-3',
'publisher': 'O''Reilly Media',
'author': 'Alex Martelli, Anna Ravenscroft, David Ascher',
},
'id5': {
'title': 'The Pragmatic Programmer: From Journeyman to Master',
'isbn': '978-0201616224',
'publisher': 'Addison-Wesley Professional (October 30, 1999)',
'author': 'Andrew Hunt, David Thomas',
},
}