题解 | 记票统计
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
看注释。
1、创建字典统计输入票数情况,然后输出。
2、注意无效票、无选票人士处理。
n = int(input())
candidate = input().split()
m = int(input())
voter = input().split()#输入数据
dic, inv = dict(), 0
for c in voter:#统计投票情况
if c in candidate:
dic[c] = dic.setdefault(c,0)+1
else:
inv += 1
for c in candidate:#输出投票统计情况
print(f'{c} : {dic.get(c,0)}')
print(f'Invalid : {inv}')#输出无效票数量
