(path: str, key: str=None)
| 8 | |
| 9 | |
| 10 | def read_jsonl(path: str, key: str=None): |
| 11 | data = [] |
| 12 | with open(os.path.expanduser(path)) as f: |
| 13 | for line in f: |
| 14 | if not line: |
| 15 | continue |
| 16 | data.append(json.loads(line)) |
| 17 | if key is not None: |
| 18 | data.sort(key=lambda x: x[key]) |
| 19 | data = {item[key]: item for item in data} |
| 20 | return data |
| 21 | |
| 22 | |
| 23 | def trim_hanging_lines(s: str, n: int) -> str: |
no test coverage detected