Sort by question id and de-duplication
(answer_file)
| 113 | fout.write(json.dumps(ans_json) + "\n") |
| 114 | |
| 115 | def reorg_answer_file(answer_file): |
| 116 | """Sort by question id and de-duplication""" |
| 117 | answers = {} |
| 118 | with open(answer_file, "r") as fin: |
| 119 | for l in fin: |
| 120 | qid = json.loads(l)["question_id"] |
| 121 | answers[qid] = l |
| 122 | |
| 123 | qids = sorted(list(answers.keys())) |
| 124 | with open(answer_file, "w") as fout: |
| 125 | for qid in qids: |
| 126 | fout.write(answers[qid]) |
| 127 | |
| 128 | |
| 129 | if __name__ == "__main__": |
no test coverage detected