kupl / apps-sal

Programming Competition Style Python Codes Datasets
MIT License
1 stars 0 forks source link

Split up `solutions.json` into Individual Python Files #12

Closed henrylee97 closed 3 years ago

henrylee97 commented 3 years ago

사용한 코드

import json
from pathlib import Path

path = Path('apps_sal/data/test') # 'apps_sal/data/train'
for prob in path.glob('*'):
    solutions_json = prob / 'solutions.json'
    if not solutions_json.exists():
        print(f'A file {solutions_json} does not exists')
        continue
    solutions_dir = prob / 'solutions'
    solutions_dir.mkdir(parents=True, exist_ok=True)
    with solutions_json.open() as f:
        solutions = json.load(f)
    for i, solution in enumerate(solutions):
        solution_py = solutions_dir / f'{i}.py'
        with solution_py.open('w') as f:
            print(solution, file=f)
    solutions_json.unlink()