题解 | #简单错误记录#

简单错误记录

https://www.nowcoder.com/practice/67df1d7889cf4c529576383c2e647c48

#学习的知识:
#一定要使用while True和try except
#split('\\')
#对字典的值从大到小进行排序:dic1=dict(sorted(dic.items(),key=lambda item:item[1],reverse=True))
#' '.join(list1)将列表内的各个string合并成一个大string
dic={}
while True:
    try:
        line=input()
        if not line:
            break
        else:
            line=line.split('\\')
            line1=line[-1] 
            if line1 in dic:
                dic[line1]=dic[line1]+1
            else:
                dic[line1]=1
    except:
        break
dic1=dict(sorted(dic.items(),key=lambda item:item[1],reverse=True))
c=0
for x in dic1:
    if c<8:
        c=c+1
        file1=x.split(' ')
        if len(file1[0])>16:
            list1=[file1[0][-16:]]+file1[1:]
            print(' '.join(list1),dic[x])
        else:
            print(x,dic[x])

全部评论

相关推荐

程序员牛肉:你这其实一点都没包装,标准的流水线产品。 实习现在不一定能解决你的问题,你太浮躁了。你看了多少源码?看了多少技术博客?真的没必要这么浮躁的着急找实习,沉下心来学习
投递实习岗位前的准备
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务