查找列表中出现次数最多的元素
点击查看代码
words = ['apple','pen','hi','banana','apple','hi','orange','apple','pen']
#导入Counter模块
from collections import Counter
count_words =Counter(words)
count_words.most_common()
#[('apple', 3), ('pen', 2), ('hi', 2), ('banana', 1), ('orange', 1)]
count_words.most_common(1)
#[('apple', 3)]

浙公网安备 33010602011771号