Python Collections库使用

1、统计列表里面各个元素的出现的次数

import collections

# list为目标列表

list = []

count = collections.counter(list)

# 统计后的count是一个字典,其中键是元素,值为其出现的次数

print count 

应用:快速计算度


发布了29 篇原创文章 · 获赞 16 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/u011412768/article/details/61915845