python篇---统计列表中每个数字的出现次数

python篇—统计列表中每个数字的出现次数

# -*- coding: utf-8 -*-
from collections import Counter


lst = ['1', '2', '3', '3', '4', '1', '2', '5', '5', '5']
count = Counter(lst)
print('每个数字在列表中的出现次数:', count)
# 再将collections.Counter格式转换成dict
print(dict(count))

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_46825740/article/details/131455179