题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
from collections import OrderedDict import re pattern=re.compile("[a-z]{1,16} \\d+") dic=OrderedDict() while True: try: s = re.search(pattern, input()).group() dic[s] = dic.get(s, 0) + 1 except: break dic=list(dic.items()) if len(dic)>8: dic=dic[-8:] for x,y in dic: print(x,y)