题解 | 记票统计
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import sys index = 0 he = set() sunhe = [] d = {"Invalid":0} for line in sys.stdin: a = line.split("\n")[0] if index == 1: aa = a.split(" ") [sunhe.append(_) for _ in aa] he = set(sunhe) if index == 3: aa = a.split(" ") for _ in aa: if _ in he: if _ not in d: d[_]=0 d[_]+=1 else: d["Invalid"]+=1 index += 1 for k in sunhe: print("%s : %s" % (k,d.get(k,0))) print("%s : %s" % ("Invalid",d.get("Invalid",0)))