Python | 列表 List 发表于 2020-12-13 更新于 2022-04-25 分类于 Python 阅读次数: Valine: 统计列表中重复项出现的次数: collections.Counter() list.count() 1234567891011121314from collections import Counterlst = ['a', 'a', 'v', 'c', 'b', 'a', 'b', 'c', 'b']Counter(lst)# Counter({'a': 3, 'v': 1, 'c': 2, 'b': 3})lst = ['a', 'a', 'v', 'c', 'b', 'a', 'b', 'c', 'b']for item in set(lst): print('the %s appears %d times' %(item, lst.count(item)))#the c appears 2 times#the v appears 1 times#the a appears 3 times#the b appears 3 times Thank you for your approval. 打赏 支付宝 微信支付 WeChat Bezahlung 欢迎关注我的其它发布渠道 WeChat