mirror of
https://github.com/buhman/nds.git
synced 2025-06-18 22:45:34 -04:00
28 lines
629 B
Python
28 lines
629 B
Python
import csv
|
|
|
|
def as_dict(header, row0):
|
|
row = [s.strip() for s in row0]
|
|
return dict(zip(header, row))
|
|
|
|
def read_input(filename):
|
|
with open(filename) as f:
|
|
reader = csv.reader(f, delimiter=",", quotechar='"')
|
|
header, *rows = reader
|
|
|
|
rows = [
|
|
as_dict(header, row)
|
|
for row in rows
|
|
if "".join(map(str, row)).strip()
|
|
]
|
|
|
|
return rows
|
|
|
|
def read_input_headerless(filename):
|
|
with open(filename) as f:
|
|
reader = csv.reader(f, delimiter=",", quotechar='"')
|
|
rows = [
|
|
[s.strip() for s in row]
|
|
for row in reader
|
|
]
|
|
return rows
|