Load a problem from a text file.
(
cls, fname: str, to_dict: bool = False, translate: bool = True
)
| 142 | |
| 143 | @classmethod |
| 144 | def from_txt_file( |
| 145 | cls, fname: str, to_dict: bool = False, translate: bool = True |
| 146 | ): |
| 147 | """Load a problem from a text file.""" |
| 148 | with open(fname, 'r') as f: |
| 149 | lines = f.read().split('\n') |
| 150 | |
| 151 | lines = [l for l in lines if l] |
| 152 | data = [ |
| 153 | cls.from_txt(url + '\n' + problem, translate) |
| 154 | for (url, problem) in reshape(lines, 2) |
| 155 | ] |
| 156 | if to_dict: |
| 157 | return cls.to_dict(data) |
| 158 | return data |
| 159 | |
| 160 | @classmethod |
| 161 | def from_txt(cls, data: str, translate: bool = True) -> Problem: |