对字符串列表进行数据频度统计,并且进行排名,选出前几名 import numpy as np li = ['cc','aa','cc','bb','aa','cc','cc','aa','cc','##','##','##'] uni = np.unique(li) # 唯一值 dic = dict((a, li.count(a)) for a in uni) # 以字典格式来显示数据频度 print(dic.items()) 结果: dict_items([('##', 3), ('aa', 3), ('bb', 1), ('cc', 5)]) dic = sorted(dic.ite