-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_json.py
More file actions
51 lines (37 loc) · 1.13 KB
/
Copy pathparse_json.py
File metadata and controls
51 lines (37 loc) · 1.13 KB
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
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat May 9 18:02:29 2020
@author: sanantha
"""
import json
with open('books.json', 'r') as f:
catalog = json.load(f)
# Print all the book identifiers
print('Task 1: Print all the book identifiers')
for book_id in sorted(catalog):
print(book_id)
print('Task 2: Show author and price of bk102')
book = catalog['bk102']
print(book['author'])
print(book['price'])
print('Task 3: Show the title of all the books')
for title in catalog.values():
print(title['title'])
print('Task 4: Show author and price of the computer books')
for book_comp in catalog.values():
if book_comp['genre'] == 'Computer':
print(book_comp['author'])
print(book_comp['price'])
print('Task 5: Show the decription of bk105')
print(catalog['bk105']['description'])
print('Task 6: Show all metadata for bk104')
book = catalog['bk104']
for tag, value in book.items():
print(tag.upper())
print(value)
print
print('Task 7: Print publishing date for bk106')
print(catalog['bk106']['publish_date'])
print('Task 8: Print the complete catalog')
print(catalog.items())