平票检测
先找最高分,再收集所有等于最高分的标签
掌握
0/5
maxitems平票
一句话
max(counts.values()) 只给最高分;要判断是否并列,必须再遍历 items,收集所有等于最高分的键。长度 1 才是唯一赢家。
它解决什么
投票合并里,平票要转人工。只取 max 的键会默认选第一个,掩盖平票。
正确顺序:top = max(counts.values());winners = [k for k, v in counts.items() if v == top];len(winners) == 1 才采纳。
平票检测
top = max(counts.values()) winners = [k for k, v in counts.items() if v == top] result = winners[0] if len(winners) == 1 else "ARBITRATE"