Counter可以用来统计list中重复元素个数,返回dict, 例如一下代码中的A, key就是词,value就是词在list中出现的个数
from collections import Counter
listExam = ['world','world','hello']
ADict = Counter(listExam)
print('---------------------ADict--------------------')
print(ADict)
wordSet = [t[0] for t in ADict.most_common(len(ADict))]
print('\n')
print('---------------------wordSet-------------------')
print(wordSet)
打印的结果如下: