Python题解 | #记票统计#

记票统计

https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894

import sys
from collections import Counter

while True:
    try:
        a = int(input())
        name = input().split(' ')
        b = int(input())
        dp = input().split(' ')
        cur1 = []
        cur2 = []
        for i in dp:
            if i in name:
                cur1.append(i)
            else:
                cur2.append(i)
        list1 = Counter(cur1)
        for i in name:
            print(f"{i} : {list1[i]}")
        print(f'Invalid : {len(cur2)}')

    except:
        break

全部评论
利用Counter函数直接生成一个字典
点赞 回复 分享
发布于 2024-05-18 21:21 上海

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务