你的代码也太奇怪了吧,comment和result的内容都不一样,怎么算有多少数量那?除此之外,你的result就不是字符串,怎么split?
我重新写了一下,你看一看吧
comments = ['不及格', '及格', '良好', '优秀']
result = '及格','优秀','良好','优秀','及格','不及格','良好','及格',\
'良好','不及格','良好','良好','良好','及格','及格','优秀',\
'优秀','良好','不及格','良好','及格','良好','及格','优秀'
resultList = list(result)
commentCnts = [0]*4
for i in range(4):
commentCnts[i] = resultList.count(comments[i])
most = max(commentCnts)
mostComment = comments[commentCnts.index(most)]
print(most, mostComment)
com = []
for i in zip(comments, commentCnts):
com.append(i)
comm = sorted(com, key=lambda a:a[1], reverse=True)
#print(comm)
print([i[0] for i in comm])
print([i[1] for i in comm])
commentCnts.sort(reverse = True)
print(commentCnts)