-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsers.py
58 lines (43 loc) · 1.42 KB
/
parsers.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
46
47
48
49
50
51
52
53
54
55
56
57
58
from clases import *
process = lambda l: list(map(int, l.split()))
def parse(file):
with open(file, 'r') as f:
lines_raw = f.readlines()
lines = list(map(process, lines_raw))
total_days = lines[0][2]
books = []
for idx, score in enumerate(lines[1]):
# info['books'][idx] = score
book = Book(idx, score)
books.append(book)
libraries = []
line_ix = 2
library_idx = 0
while line_ix < len(lines):
if len(lines[line_ix]) == 0:
break
_, treg, rate = lines[line_ix]
line_ix += 1
books_idx = lines[line_ix]
books_ = [books[ix] for ix in books_idx]
library = Library(library_idx, books_, treg, rate)
libraries.append(library)
# info['libraries'][library_idx] = {
# 'treg': treg,
# 'rate': rate,
# 'books': books}
line_ix += 1
library_idx += 1
return books, libraries, total_days
def escribir_resultado(salida, filename='output.txt'):
output = open(filename, 'w')
salida_f = list(filter(lambda x: len(x[1]) > 0, salida))
output.write(f'{len(salida_f)}\n')
for library, books in salida_f:
output.write(f'{library.id} {len(books)}\n')
for book in books:
output.write(str(book.id) + ' ')
output.write('\n')
output.close()
if __name__ == '__main__':
d = parse('input_data/b_read_on.txt')