题解 | #简单错误记录#

简单错误记录

http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb

import sys
my_dict = {}
mistake = []
value = []
while True:
    line = sys.stdin.readline().strip().split('\\')[-1]
    if line == '':
        break
    elif line in mistake:
        value[mistake.index(line)] = value[mistake.index(line)] + 1
    else:
        mistake.append(line)
        value.append(1)

for i in range(len(mistake)):
    item = mistake[i].split()[0]
    if len(item) > 16:
        newitem = item[-16:] + ' ' + mistake[i].split()[1]
        if newitem in mistake:
            value[mistake.index(newitem)] = value[mistake.index(newitem)] + 1
            value.pop(i)
            mistake.pop(i)
        else:
            mistake[i] = newitem

if len(mistake) > 8:
    re_mistake = mistake[-8:]
    re_value = value[-8:]
else:
    re_mistake = mistake
    re_value = value
for i in range(len(re_value)):
    print(re_mistake[i] + ' ' + str(re_value[i]))

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-21 17:16
科大讯飞 算法工程师 28.0k*14.0, 百分之三十是绩效,惯例只发0.9
点赞 评论 收藏
分享
牛客339922477号:都不用reverse,直接-1。一行。啥送分题
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务