| 1 | import os |
| 2 | |
| 3 | |
| 4 | def parse_file(path): |
| 5 | records = [] |
| 6 | with open(path) as f: |
| 7 | for line in f: |
| 8 | line = line.strip() |
| 9 | if not line: |
| 10 | continue |
| 11 | name, value = line.split(",") |
| 12 | records.append((name.strip(), int(value))) |
| 13 | return records |
| 14 | |
| 15 | |
| 16 | def parse_all(directory): |
| 17 | """All (name, value) records across every data file in directory, sorted.""" |
| 18 | records = [] |
| 19 | for entry in sorted(os.listdir(directory)): |
| 20 | records.extend(parse_file(os.path.join(directory, entry))) |
| 21 | return sorted(records) |
| 22 |