题解 | #记票统计#
记票统计
http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
新手入门
def peple_count(a,b,c,d): Invalid = 0 dic = {} e = [] for i in d : # 判断无效票数 if i not in b : Invalid += 1 # 将有效票存于列表e else : e.append(i) # 利用字典计算每张有效票出现的次数 for i in e : dic[i] = dic.get(i,0) + 1 # 参选人无人投票的的情况: for i in b : if i not in e : dic[i] = dic.get(i,0) # 打印 for i in b : print(f'{i} : {dic[i]}') print(f'Invalid : {Invalid}') a = int(input().strip()) b = input().strip().split() c = int(input().strip()) d = input().strip().split() peple_count(a,b,c,d)