-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
35 lines (30 loc) · 825 Bytes
/
script.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
import json
import csv
with open('../users.json', "r") as users_file:
users = json.load(users_file)
result = []
for user in users:
result.append(
{
'name': user['name'],
'gender': user['gender'],
'address': user['address'],
'age': user['age'],
'books': []
}
)
with open('../books.csv', "r") as books_file:
books = csv.DictReader(books_file)
i = 0
for book in books:
result[i % len(result)]['books'].append(
{
'title': book['Title'],
'author': book['Author'],
'pages': book['Pages'],
'genre': book['Genre']
}
)
i += 1
with open('result.json', 'w') as result_file:
json.dump(result, result_file, indent=4)