Python articles---count the number of occurrences of each number in the list

Python articles - count the number of occurrences of each number in the list

# -*- 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))

insert image description here

Guess you like

Origin blog.csdn.net/m0_46825740/article/details/131455179