多数投票(pyrhon)

import operator
def majorityCnt(classList):
    classCount={}
    for vote in classList:
        if vote not in classCount:
            classCount[vote]=1
        else:
            classCount[vote]+=1
    sortedClassCount=sorted(classCount.items(),key=operator.itemgetter(1),reverse=True)
    return classList[0][0]

猜你喜欢

转载自blog.csdn.net/qq_39394809/article/details/85094800