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