python中统计列表中元素出现的次数
>>> test1 = ["aaa","bbb","aaa","aaa","ccc","ccc","ddd","aaa","ddd","eee","ddd"]
>>> test1.count("aaa") ## 统计指定元素出现的次数
4
>>> test1.count("bbb")
1
>>> test2 = []
>>> for i in test1: ## 去重复
if i not in test2:
test2.append(i)
>>> test2
['aaa', 'bbb', 'ccc', 'ddd', 'eee']
>>> for i in test2: ## 统计每一个元素出现的次数
print(f"{i}:{test1.count(i)}")
aaa:4
bbb:1
ccc:2
ddd:3
eee:1
>>>