我需要比较存储在一个数组中的数据计数,以确定投票系统中的平局
if votes.count(1) == votes.count(2) or votes.count(1) == votes.count(3) or votes.count(1) == votes.count(4) or votes.count(2) == votes.count(1) or votes.count(2) == votes.count(3) or votes.count(2) == votes.count(4) or votes.count(3) == votes.count(1) or votes.count(3) == votes.count(4) or votes.count(3) == votes.count(2) or votes.count(4) == votes.count(1) or votes.count(4) == votes.count(3) or votes.count(4) == votes.count(2):
投票将以数字形式存储在数组中。因此,如果您投票给第一位候选人,它将存储为“1”,依此类推。我想知道是否有一种更简单的方法来检查不是所有的候选人之间是否存在平局,例如两名候选人
存储每个元素的计数,并以列表的形式存储它们。然后选中“使用集合删除重复项”,并检查集合的长度是否等于列表
试试这样的
但我建议使用字典:
如果你想知道票数相等的候选人,试试这个:
相关问题 更多 >
编程相关推荐