_utils.py 559 B

12345678910111213141516171819
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from typing import List, Dict
  4. def complete_answer_statistic(answers: List[Dict[str, int]]) -> List[Dict[str, int]]:
  5. """
  6. 补全答案统计数据
  7. """
  8. answer_set = set(["A", "B", "C", "D"])
  9. if len(answers) != 4:
  10. exist_answer_set = set([x["key"] for x in answers])
  11. lack_answer_set = answer_set - exist_answer_set
  12. if lack_answer_set:
  13. answers.extend([{"key": x, "val": 0} for x in lack_answer_set])
  14. answers.sort(key=lambda x: x["key"])
  15. return answers